Search Unity

Bug EntityManager.ExclusiveEntityTransactionDependency must depend on the Entity Transaction job.

Discussion in 'Entity Component System' started by alfiare, Jan 25, 2023.

  1. alfiare

    alfiare

    Joined:
    Feb 10, 2017
    Posts:
    30
    Using the new Entities 1.0 package and Unity 2022.2.1f1 I am attempting to use a job to execute a command buffer on a world (the idea of a loading world), the world isn't in the player loop or anything. Here's the code of the job itself (not much to it)...

    Code (CSharp):
    1. struct ExecuteCreatesCommandBufferJob : IJob
    2.         {
    3.             public ExclusiveEntityTransaction EET;
    4.             public EntityCommandBuffer CB;
    5.  
    6.             public void Execute()
    7.             {
    8.                 CB.Playback(EET);
    9.             }
    10.         }
    I start it like this (_world is the ECS world)...

    Code (CSharp):
    1. ExclusiveEntityTransaction eet = _world.EntityManager.BeginExclusiveEntityTransaction();
    2.             ExecuteCreatesCommandBufferJob executeJob = new ExecuteCreatesCommandBufferJob() { CB = _createCommandBuffer, EET = eet };
    3.             EntityManager entityManager = _world.EntityManager;
    4.             entityManager.ExclusiveEntityTransactionDependency = executeJob.Schedule();
    When that last line executes I get an error in the unity console...

    InvalidOperationException: EntityManager.ExclusiveEntityTransactionDependency must depend on the Entity Transaction job.
    Unity.Entities.ComponentDependencyManager.set_ExclusiveTransactionDependency (Unity.Jobs.JobHandle value) (at Library/PackageCache/com.unity.entities@1.0.0-pre.15/Unity.Entities/ComponentDependencyManager.cs:574)
    Unity.Entities.EntityManager.set_ExclusiveEntityTransactionDependency (Unity.Jobs.JobHandle value) (at Library/PackageCache/com.unity.entities@1.0.0-pre.15/Unity.Entities/EntityManagerExclusiveEntityTransaction.cs:34)

    This seems like a bug or am I doing something wrong? This worked fine in the previous version of ECS.
     
  2. elliotc-unity

    elliotc-unity

    Unity Technologies

    Joined:
    Nov 5, 2015
    Posts:
    230
    Looking at the usages elsewhere, the correct way is probably

    entityManager.ExclusiveEntityTransactionDependency = executeJob.Schedule(entityManager.ExclusiveEntityTransactionDependency));
    For example, AsyncLoadSceneOperation.cs does

    var loadJobHandle = loadJob.Schedule(JobHandle.CombineDependencies(
    _EntityManager.ExclusiveEntityTransactionDependency,
    _ReadHandle.JobHandle));
    _EntityManager.ExclusiveEntityTransactionDependency = loadJobHandle;

    Basically I think there's some preexisting job handle represented by the previous value of EETD, and the check is checking that you didn't lose that when you're assigning to it now. Can you confirm that it works if you do that? I can fix the error message in the meantime.
     
  3. alfiare

    alfiare

    Joined:
    Feb 10, 2017
    Posts:
    30
    That was the answer, works once I get that dependency in the Schedule call, thank you!
     
    elliotc-unity likes this.