A barrier is a sync point. It holds one or many EntityCommandBuffers that other jobs can use. It will then playback these buffers when the barrier gets updated. You'll need to use a barrier when updating entities (adding/removing components, creating/destroying entities) from jobs. See more here.
Thx for an explanation and a reference link. I have been on that page before, but perhaps was too early for me, to grasp it.
Here is an article that explains in more detail: https://gametorrahod.com/unity-ecs-...arriersystem-entitycommandbuffer-3770e2823290
I read once, to get some light on my understanding. But definitely I need to re read at least once or twice more. Nice to see examples.
To the above reference, I would like to appoint also the tutorial, which I followed recetly, to help me understand Barriers and ECS + Job System in practice. Unity - using the Job System with ECS However, it feels for me a bit vague, official references are worth to be mentioned too ECS features in detail https://github.com/Unity-Technologi...ocumentation/content/ecs_in_detail.md#barrier
Wondering if someone could help me find a good example for creating a barrier system that deletes components. (most links in the thread are now 404s). Not sure if there is something special about them. Here is what im thinking: I have some components VertexComponent and TriangleComponent that is created via subscense live linking at runtime. Several system use this data but only need to use it once ( building a mesh set some relationships for pathfinding). I thought it might be a good idea to run a barrier system after all my system are done with these components and remove the these components. This way these system will only run once when adjusting my live link game objects. Im I in the ballpark here or is this a bad idea. edit : added my attempt Code (CSharp): using Unity.Collections; using Unity.Entities; using Unity.Jobs; namespace NDA.HexWorld { public class HexSphereBuildBarrierSystem : JobComponentSystem { #region FLIELDS -------------------------------------------------------- [ReadOnly] private EntityManager em; [ReadOnly] private EntityQuery eqVertexComp; [ReadOnly] private EntityQuery eqTriangleComp; #endregion #region METHODS -------------------------------------------------------- /// <summary> /// Constructor for system. /// </summary> protected override void OnCreate() { base.OnCreate(); // // Create EntityManager em = World.Active.EntityManager; // // Add system World.Active.GetOrCreateSystem<BeginSimulationEntityCommandBufferSystem>(); // // Create Entity EntityQuery eqVertexComp = em.CreateEntityQuery(ComponentType.ReadOnly<VertexComponent>()); eqTriangleComp = em.CreateEntityQuery(ComponentType.ReadOnly<TriangleComponent>()); } #endregion #region MAIN THREAD ------------------------------------------------------ protected override JobHandle OnUpdate(JobHandle inputDeps) { // // Remove hex vertex and triangle components so the system doen not run jobs EntityManager.RemoveComponent(eqVertexComp, typeof(VertexComponent)); EntityManager.RemoveComponent(eqTriangleComp, typeof(TriangleComponent)); return inputDeps; } #endregion } } and my other systems use [UpdateBefore(typeof(HexSphereBuildBarrierSystem))]
Well classical (U2018) inject barrier become obsolete in U2019. https://docs.unity3d.com/Packages/com.unity.entities@0.0/manual/entity_command_buffer.html Not the best link, but gives you good starting point. Then look into defaultWorld.cs for some ideas. Probably for best performance, it would be better to have empty component as tag(s), which indicates that your data is removed/added. This way you don't need move entity between chunks, when adding/removing component with data. You basically wan EntityCommandBuffer ecb. And similarly as Entity Manager, you can manipulate components. ecb.AddComponentData for example.