Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question When I get his index after instantiate entity, I always get -1

Discussion in 'Entity Component System' started by keepupalltime, Jul 25, 2023.

  1. keepupalltime

    keepupalltime

    Joined:
    Apr 17, 2020
    Posts:
    6
    I instantiate enity in job, I get the index of entity is -1. Shouldn't index be different?
    Code (CSharp):
    1. [BurstCompile]
    2. private void Execute([ChunkIndexInQuery] int chunkIndex)
    3. {
    4.     Entity entity = ecb.Instantiate(chunkIndex, prefab);
    5.     int index = entity.Index;
    6.     UnityEngine.Debug.Log(">>>>>>>>>> " + index);
    7. }
    >>>>>>>>>> -1
     
  2. julian-moschuering

    julian-moschuering

    Joined:
    Apr 15, 2014
    Posts:
    529
    The actual entity creation happens during ECB playback. While recording, each ECB creates 'fake' entities only usable within the context of the ECB. If you execute another
    Instantiate
    on the same ECB it would get index -2.
    The entity returned is not usable for anything except for queing additional commands on the same ECB.
     
  3. keepupalltime

    keepupalltime

    Joined:
    Apr 17, 2020
    Posts:
    6
    Oh, I see. Thank you very much