Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Entity component data not getting set from within job

Discussion in 'Entity Component System' started by Init33, Jul 12, 2019.

  1. Init33

    Init33

    Joined:
    Aug 30, 2017
    Posts:
    67
    I am having a weird issue and I think it ultimately comes down to not really understanding concurrent command buffers and entities / entity versions.

    In my system I have a job which gets entities and does the following commands on them:

    Code (CSharp):
    1. public struct FinaliseRoad : IJobForEachWithEntity<RoadCurrentlyBuilding, RoadDisplay>
    2. {
    3.     [ReadOnly] public EntityCommandBuffer.Concurrent CommandBuffer;
    4.  
    5.     public void Execute(Entity entity, int index, [ReadOnly] ref RoadCurrentlyBuilding c0, ref RoadDisplay r)
    6.     {
    7.         CommandBuffer.RemoveComponent<RoadCurrentlyBuilding>(index, entity);
    8.         RoadDisplay tempR = r;
    9.         r.placing = 0;
    10.         CommandBuffer.SetComponent(index, entity, tempR);
    11.     }
    12. }
    When this code runs, I can see that the entities have had "RoadCurrentlyBuilding" removed but "r.placing" is still showing up as 1 (what the entities are initialised with). I don't believe that there is anywhere else in my project that modifies the "RoadDisplay" component. The code above successfully removes component data (even if there are multiple components to remove) but doesn't seem to be able to set the "RoadDisplay" component data.

    Any ideas why this is happening?
     
  2. Init33

    Init33

    Joined:
    Aug 30, 2017
    Posts:
    67
    Sorry I'm a dingus, I was modifying the wrong value "r.placing" instead of "tempR.placing". Disregard this thread (why can i not delete -_-)