Search Unity

How to: Create two entities in a job and parent one to the other?

Discussion in 'Data Oriented Technology Stack' started by PublicEnumE, Aug 17, 2019.

  1. PublicEnumE

    PublicEnumE

    Joined:
    Feb 3, 2019
    Posts:
    173
    The Entity values returned by EntiyCommandBuffer.Concurrent.CreateEntity() or Instantiate() are temporary - only good for issuing further ECB commands to set that Entitiy’s component data, from the job. Once the ECB actually creates the Entity on the main thread, it becomes a real boy and is given a new ID that can co-exist with other Entities in the world. That makes sense!

    But what if you want to store a persistent reference to the Entity you just queued up to be made, in the same job where you just issued the command?

    What if you want to link two or more temp Entity’s together, say, by parenting one to the other?

    My actual problem case: I’d like to instantiate a single ‘root’ Entity, and then a variable ‘n’ number of child entities, and then parent all the children to the root. All from a job.

    - - -

    If I knew the exact number of child entities, I could potentially do this by instantiating a preconfigured prefab. But since I will never know how many child entities the user want to create, this probably won’t work - at least not without overestimating the number of entities I need and padding the prefab with extra children.

    - - -

    What would you do? Is there a good way to ‘resolve’ the value of a temp Entity into its real value after ECB has created it?

    It’s been a while since the ECB was refactored with this pattern, so maybe people have figured this one out. :)

    Thank you for any help!
     
  2. PublicEnumE

    PublicEnumE

    Joined:
    Feb 3, 2019
    Posts:
    173
  3. PublicEnumE

    PublicEnumE

    Joined:
    Feb 3, 2019
    Posts:
    173
unityunity