EntityManager.ExclusiveEntityTransactionDependency must depend on the Entity Transaction job.

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)…

struct ExecuteCreatesCommandBufferJob : IJob
        {
            public ExclusiveEntityTransaction EET;
            public EntityCommandBuffer CB;

            public void Execute()
            {
                CB.Playback(EET);
            }
        }

I start it like this (_world is the ECS world)…

ExclusiveEntityTransaction eet = _world.EntityManager.BeginExclusiveEntityTransaction();
            ExecuteCreatesCommandBufferJob executeJob = new ExecuteCreatesCommandBufferJob() { CB = _createCommandBuffer, EET = eet };
            EntityManager entityManager = _world.EntityManager;
            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.

Looking at the usages elsewhere, the correct way is probably

``` 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.

That was the answer, works once I get that dependency in the Schedule call, thank you!

1 Like