Search Unity

Creating an Entity via ECB and then getting that Entity?

Discussion in 'Entity Component System' started by jwvanderbeck, Jun 30, 2020.

  1. jwvanderbeck

    jwvanderbeck

    Joined:
    Dec 4, 2014
    Posts:
    825
    I have a method on a GO that creates an Entity on request. The creation of this entity has a lot of sub parts to it including dynamic buffers and components, that make it tricky to do straight up, so I use an ECB.

    However, I want to create this Entity and then report back to the caller and pass the Entity that was created. Despite this all being on main thread and me calling Playback in the method, I'm guessing that the ACTUAL execution of the ECB doesn't occur until some other point because while the variable I assign to the new Entity does get populated with data, its in a format such as -entity,v0. Presumably the ECB figures that out later.

    So my question is, what sorts of methods do people use/suggest for making a call to create an Entity say from a UI or other Non-Entities GO, and then know which Entity you just created.

    Are there any existing mechanisms here I could take advantage of? One sort of half-baked idea I thought of was maybe generating some sort of GUID that the caller passes in, then that gets placed into a component on the entity. Then the caller could do a query after for that GUID, but this seems rather inefficient.
     
  2. RoughSpaghetti3211

    RoughSpaghetti3211

    Joined:
    Aug 11, 2015
    Posts:
    1,705
    I usually just tag it with an empty component
     
    MhmdAL1111 likes this.
  3. WAYNGames

    WAYNGames

    Joined:
    Mar 16, 2019
    Posts:
    992
    If you are on hte main thread why not use the entity manager ? especcially if you play back the buffer rigth after.
    Nothing prevent you from creating an empty entity and then use it you your subsequent command buffer.
    The creation from the entity manager is immediate as far as I know so you should get the real entity reference from it.
     
  4. steve56

    steve56

    Joined:
    Jun 30, 2020
    Posts:
    2
    Thank you for the dertails.
     
  5. steve56

    steve56

    Joined:
    Jun 30, 2020
    Posts:
    2
    Thank you for the dertails.
     
  6. jwvanderbeck

    jwvanderbeck

    Joined:
    Dec 4, 2014
    Posts:
    825
    To be honest, I didn't even think to create the entity outside the buffer and then do everything else inside the buffer :)