-
Notifications
You must be signed in to change notification settings - Fork 115
Removing entity crashes program #175
Comments
With the order you have initially |
But the TransformSystem should not operate on removed entities/components because I didn't set the true flag. This is my intention, once I flag an entity for removal it should not be operated on on the following systems but as you can see in my first error message, it does it anyway. It seems the components get removed but the entity is still alive. Thus resulting in undefined components. |
So in tha case you should change your queries to skip the entities that has the |
I am lost. Why do the queries match after DestroySystem? They should not match because the components were removed. They should match the removed query but I am not using that query in the systems after DestroySystem. EDIT: I think I get it, the actual entity doesn't get removed untill the end of the frame thus resulting in the error. I thought the actual entity also would not show up in the systems following DestroySystem. But how does it work because when I do entity.remove() ALL components get removed even EDIT "If you remove the component on DestroySystem the entity will get removed and all its components too" reading this again it doesn't seem to make sense, if an entity is flagged as removed why would it still show up in the systems following |
They will show up on |
(*) Just to clarify the comment you mention. When I say |
Yeah right, but I am not using EDIT: Here you can see the problem most likely. The |
I just realized one issue, if you are removing entities or components within the list you are traversing, you are mutating it and you can't just use query = [1,2,3,4];
queryforEach(i => query.splice(query.indexOf(i), 1));
// query = [2,3] you should traverse it in the inverse order: for (i = results.length - 1; i > 0; i--) {
results[i].remove()
} I can't join on discord right now, but I'll prepare a logger that shows the steps you are going into so you can paste them here, and probably tomorrow we could talk if so. |
Still getting the errors even with this loop :( EDIT: I've located the error, I'm sure the changed and added queries still hold on to the entity.alive = false entities. I don't see the error when I do a quick fix like so: for (let i = this.queries.colliding.added.length - 1; i >= 0; --i) {
this.queries.colliding.added[i].remove();
}
for (let i = this.queries.entities.added.length - 1; i >= 0; --i) {
// @ts-ignore
if (this.queries.entities.added[i].alive)
this.queries.entities.added[i].remove();
} So for now I use that if statement before removing + placing DestroySystem all the way at the top as a quick fix until the problem is fixed. It seems it's the same error as #138 |
Tagging this as bug and I'll keep track of it. There is a concept of |
Awesome. I expected it to be a 'simple' fix tho, filtering the query entities for their alive state before returning it but it seems it's more complex than that? Do you have an estimation for when this bug would be resolved? |
The problem is that there is not really a perfect answer to what to expect when you add and remove an entity within the same frame. Like in your case you would expect it to not appear on |
I understand. It would, to me, be most intuitive if the entity after explicitly typing Appreciate all the work and communication! |
I am working on my projectile system. I am destroying projectiles after a timeout and on colliding with another object. I keep getting error messages and I suspect the flaw is within ecsy itself. Currently my code looks like this:
WeaponSystem.ts
DestroySystem.ts
When I try this order of registering my systems:
I get the following error:
Using the following queries in TransformSystem.ts
When I put the DestroySystem all the way at the top like so:
It appears to work (other than the rendering system rendering an already destroyed object) but after a couple of seconds of shooting I get:
I hope this is enough information to discover the flaw, my source can be found here: https://github.com/nickyvanurk/3d-multiplayer-browser-shooter/tree/master/client/src
The text was updated successfully, but these errors were encountered: