Search Unity

Invalid entity (DELETED) error!

Discussion in 'Project Tiny' started by leeham9, Jan 17, 2019.

  1. leeham9

    leeham9

    Joined:
    Oct 25, 2015
    Posts:
    12
    Hi all,

    I've been stuck for a little while on this issue that keeps breaking my game. Basically, I'm using this.world.DestroyEntity(entity) on an "Enemy", but when I call this the game freezes and I get these errors:

    https://gyazo.com/aa571752c0d974382c9ef3893a4c4043

    Here is the chunk of code I call too:

    https://gyazo.com/9c9416c925145a94ea9c172e4fbacab4

    I feel like I've looked all over in my code (there's only a few Systems right now), and I'm really confused as to why this is happening. I call this.world.DestroyEntity(entity) on a "Bullet" entity I have, and it works perfectly fine.

    Does anyone have any idea what might cause this error message? I feel like its something pretty simple/silly, but unfortunately I'm in crunch-mode and feel like I'm not thinking straight...
     
  2. leeham9

    leeham9

    Joined:
    Oct 25, 2015
    Posts:
    12
    I think I've found whats causing this, but I don't have a solution just yet. But basically, I have a "Weapon" which is nested in "Enemy" and it seems that when I destroy enemy, code associated with the weapon seems to cause this error.
     
  3. Nkon

    Nkon

    Unity Technologies

    Joined:
    Jun 12, 2017
    Posts:
    65
    Hi there,

    You need to move all children of an entity to another location in the hierarchy before you destroy the entity, or alternatively also destroy the children together with the parent entity.

    Move all children of an entity to the root level of the hierarchy:
    ut.Core2D.TransformService.removeAllChildren(this.world, entity);


    Destroy any children together with the parent entity:
    ut.Core2D.TransformService.destroyTree(this.world, entity);


    Cheers!
     
    Last edited: Jan 18, 2019
    leeham9 likes this.
  4. leeham9

    leeham9

    Joined:
    Oct 25, 2015
    Posts:
    12
    Thanks Nkon! I did end up coming up with a solution, but I didn't know about the removeAllChildren or destroyTree methods. Those are super useful.
     
  5. raymondyunity

    raymondyunity

    Unity Technologies

    Joined:
    Apr 30, 2018
    Posts:
    98
    Hey,
    I'm glad this was resolved. After some digging it looks like "this.world.DestroyEntity(entity)" is not working as expected. Use "ut.Core2D.TransformService.destroyTree(this.world, entity);". This is also how the current samples are destroying entities.
     
    abeisgreat likes this.
  6. ju_my

    ju_my

    Joined:
    Mar 7, 2017
    Posts:
    11
    Hi, how do you access "ut" i can't find it anywhere?