-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When calling Entity.Delete(), the entity passed to EntitySystem.OnRemoved does not contain any components. #99
Comments
Try the following: if (this.RemovedEntityEvent != null)
{
this.RemovedEntityEvent(entity);
} up. Place it before Thus you could subscribe your systems to EntityManager.RemovedEntityEvent (not the OnRemoved override) and in the handler you could Get any component you like. Ignore subsequent OnRemoved method call. Yes, there still would be an issue if you try to access Tag or Group of the entity - but the problem with Components seems to be solved that way. |
Thank you for the prompt reply! As to your suggestion, wouldn't this be a bit inefficient? Take a bullet-hell shooter, for example. With hundreds of bullets deleted every frame, subscribing a non-bullet system to EntityManager.RemovedEntityEvent would be unwise. I am currently investigating whether I can call EntitySystem.OnRemoved() inside EntityManager.Remove itself. As for now, I have held off on doing cleanup code inside the OnRemoved() override, instead I am doing cleanup before Entity.Delete() is called using extension methods. |
Even without subscription to EntityManager.RemovedEntityEvent every EntitySystem gets internal OnChange(Entity entity) method call with every entity that has been changed or deleted. ...
bool contains = (this.SystemBit & entity.SystemBits) == this.SystemBit;
bool interest = this.Aspect.Interests(entity);
... So if you do subscribe to EntityManager.RemovedEntityEvent, you could filter out "bullets" in non-bullet systems (though some work on access modifiers would be required to use same quick check). BTW could you post here your cleanup extension method please? Just curios. |
Sure! It's for a scene graph system I use for rendering hierarchical sprites.
I was originally going to put it in an OnRemoved override for the system that handles SceneGraphComponents. |
Sample code:
The components should be accessible during the call to OnRemoved, so that the system can have a chance to clean up.
I think this is related to Issue #49.
In EntityWorld.Update, the following code is called:
before this
this.EntityManager.Refresh(entity);
Thus, OnRemove is called with an empty Entity.
I have tried coming up with a solution, but my knowledge of Artemis' internals is still too limited.
Thank you!
The text was updated successfully, but these errors were encountered: