Search Unity

Queries created in OnCreate prevent IJobForEach System from running

Discussion in 'Entity Component System' started by pakfront, May 18, 2019.

  1. pakfront

    pakfront

    Joined:
    Oct 6, 2010
    Posts:
    551
    It appears that creating queries in OnCreate interferes with the automatic generation of a query from IJobForEach.

    I am creating a query on the system object in OnCreate that I conditionally use with EntityManager.RemoveComponent. It is not used with any Jobs. If I don't create the query, the system runs as normal, and the IJobForEach query shows up in the entity debugger.
    If I do create it, the system is 'not run' and only the custom query shows up in the debugger. This is true whether or not I actually use the query in OnUpdate. Is this expected? I don't see anything about it in the docs.


    Code (CSharp):
    1.  
    2.        protected override void OnCreate()
    3.        {
    4.             base.OnCreate();
    5.             m_GroupPlayerSelected = GetEntityQuery(new EntityQueryDesc
    6.             {
    7.                 All = new ComponentType[] { ComponentType.ReadOnly<PlayerSelected>() }
    8.             });
    9.         ...
    10.         [RequireComponentTag(typeof(Unit))]
    11.         [ExcludeComponent(typeof(PlayerSelected))]
    12.         struct PlayerSelectionJob : IJobForEachWithEntity<AABB>
    13.         ...
    14.  
    15.        protected override JobHandle OnUpdate(JobHandle inputDeps)
    16.       {
    17.           // EntityManager.RemoveComponent(m_GroupPlayerSelected,ComponentType.ReadOnly<PlayerSelected>());
    18.            var job = new PlayerSelectionJob
    19.             ...
    20.            var outputDeps = job.Schedule(this, inputDeps);
    21.  
    22.            m_EntityCommandBufferSystem.AddJobHandleForProducer(outputDeps);
    23.            return outputDeps;
    24.  
    25.  
     
    Last edited: May 18, 2019
  2. pakfront

    pakfront

    Joined:
    Oct 6, 2010
    Posts:
    551
    I worked around this for the moment by moving the EntityManaget.RemoveComponent into a ComponentSystem (not Job). Maybe that's more appropriate anyway?
     
    Last edited: May 18, 2019
  3. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,685
    upload_2019-5-20_9-12-0.png

    1. Your system run without query cos systems without query == Always Update, and it runs first time with this behaviour and generate new EntityQuery on IJobForEach and after that you can see IJobForEach query in debugger.
    2. When you declare your EQ it runs only by this EQ until IJobForEach runs once and generate his EQ.
    You can create EQ for IJobForEach explicitly
     
  4. pakfront

    pakfront

    Joined:
    Oct 6, 2010
    Posts:
    551
    Thanks, that makes sense.