Search Unity

How safe are command buffers?

Discussion in 'Entity Component System' started by spectre1989, Oct 17, 2019.

  1. spectre1989

    spectre1989

    Joined:
    Oct 6, 2009
    Posts:
    125
    Hi all,

    I've been watching some of the Unite talks, and something occurred to me. What if I have 2 jobs which modify the same entity via command buffers, let's say one sets some component data, and the other destroys the entity. What if the entity is destroyed before the component data is set? I was under the impression that an entity is just an index for component data arrays? If that's the case could I end up setting data on the wrong entity if the entity id is reused?
     
  2. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,759
    That isn't an issue. Entity are defined by both an index and a version. When an index is re-used the version number is incremented. For the life of the application, 2 entities will never be identical when both index and version are considered (and this is why you should not identify entities by just index.)

    As for your original question, I actually can't remember. In the past it'd throw an exception but you could control this by simply having the job that destroys run after the job that modifies the component.

    However I can't remember if this behavior changed at some point and fails silently. I think I recall this being the case with 2 different jobs adding a component to an entity. I don't use ECB much at the moment (and when I do the way I design systems this would not come up) so it's a bit blurry for me, I'm sure someone else can chime in with a more definitive answer.
     
    spectre1989 likes this.
  3. spectre1989

    spectre1989

    Joined:
    Oct 6, 2009
    Posts:
    125
    Ah ha that makes sense, ok thanks :)