ECS sync points

Sync points
All structural changes have hard sync points. CreateEntity, Instantiate, Destroy, AddComponent, RemoveComponent, SetSharedComponentData all have a hard sync point. Meaning all jobs scheduled through JobComponentSystem will be completed before creating the entity, for example. This happens automatically. So for instance: calling EntityManager.CreateEntity in the middle of the frame might result in a large stall waiting for all previously scheduled jobs in the World to complete.

What about GetComponentData?

Only when first AddReaderWriter registred

        public ComponentDataFromEntity<T> GetComponentDataFromEntity<T>(bool isReadOnly = false)
            where T : struct, IComponentData
        {
            AddReaderWriter(isReadOnly ? ComponentType.ReadOnly<T>() : ComponentType.ReadWrite<T>());
            return EntityManager.GetComponentDataFromEntity<T>(isReadOnly);
        }
internal void AddReaderWriter(ComponentType componentType)
        {
            if (CalculateReaderWriterDependency.Add(componentType, ref JobDependencyForReadingSystemsUnsafeList,
                ref JobDependencyForWritingSystemsUnsafeList))
            {
                CompleteDependencyInternal();
            }
        }
1 Like

After the register, there will be a partial sync point in which all jobs scheduled to write to the component type specified by your GetCompoonentData will be completed.

1 Like

Does this happen at the beginning or every frame? What would be the difference in sync points between using GCDFE and GCDFE(true)?

For CDFEs, this happens only the first time the system calls GCDFE. Subsequent updates it remembers that component type as a dependency and the appropriate JobHandle gets merged into Dependency before the OnUpdate callback. In either case, which JobHandle gets used (either completed or merged) depends on that readOnly parameter. If true, then only the last recorded JobHandle that wrote to the component is used. If false, then the last recorded JobHandle that read or wrote to the component is used. Try to specify readOnly = true whenever possible.

1 Like