Search Unity

When does the barrier CommandBuffer executes a Query?

Discussion in 'Data Oriented Technology Stack' started by rsodre, Aug 25, 2019.

  1. rsodre

    rsodre

    Joined:
    May 9, 2012
    Posts:
    198
    I'm starting to replace my CommandBuffers for the recommended barriers, but I don't understand exactly when it executes the query. When we add to the CB or on Playback?

    Example:

    System 1: Add some entities to be destroyed by EndSimulationEntityCommandBufferSystem, using a query that returns 10 entities.
    System 2: Create 5 entities that will fit que query to be destroyed in System 1.
    EndSimulationEntityCommandBufferSystem: Will it destroy entities created in System 2?
     
  2. digitaliliad

    digitaliliad

    Joined:
    Jul 1, 2018
    Posts:
    63
    I'm not sure exactly about your stated case: lots of missing information; when do the systems update?

    I do believe can do something like this:
    Code (CSharp):
    1. public class SomeSystem : ComponentSystem
    2. {
    3.     private EntityQuery query;
    4.     protected override void OnCreate()
    5.     {
    6.         query = GetEntityQuery(ComponentType.ReadOnly<CompA>(), ComponentType.ReadOnly<CompB>());
    7.     }
    8.     protected override void OnUpdate()
    9.     {
    10.         // This should succeed.
    11.         PostUpdateCommands.RemoveComponent<CompA>(query);
    12.         // This won't occur, I think.
    13.         PostUpdateCommands.RemoveComponent<CompB>(query);
    14.     }
    15. }
    thereby invalidating your query during the buffer playback.

    P.S., obviously there's more to testing this, but I feel like I've accidentally done this to myself, before.
     
  3. rsodre

    rsodre

    Joined:
    May 9, 2012
    Posts:
    198
    The systems update in that order, inside the Simulations group.

    My question is when commands passed to an EndSimulationEntityCommandBufferSystem CommandBuffer using queries are parsed, at the moment I create the command, or when it is played back, at the end of the frame?
    Because between creating the commands and playback, the query results may change.
     
    Last edited: Aug 27, 2019
  4. digitaliliad

    digitaliliad

    Joined:
    Jul 1, 2018
    Posts:
    63
    I'm not sure, but I certainly believe you can invalidate your query between when you create the commands, and when they play back.
     
  5. RecursiveEclipse

    RecursiveEclipse

    Joined:
    Sep 6, 2018
    Posts:
    120
    It plays back when the Barrier/BufferSystem you got the buffer from runs. Plays back meaning all the commands get executed & entities are created.
     
unityunity