Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question 1.0 User created ECB system

Discussion in 'Entity Component System' started by Mayumichi, Nov 9, 2022.

  1. Mayumichi

    Mayumichi

    Joined:
    Mar 12, 2017
    Posts:
    31
    The documentation says to leave the system body empty like this

    Code (CSharp):
    1.  
    2. [UpdateInGroup(typeof(SimulationSystemGroup))]
    3. [UpdateAfter(typeof(FooSystem))]
    4. public class MyECBSystem : EntityCommandBufferSystem {
    5.     // This class is intentionally empty. There is generally no
    6.     // reason to put any code in an EntityCommandBufferSystem.
    7. }
    but you don't get the new singleton this way which seems to be required to use it in ISystem? The pre-existing systems decompile to this

    Code (CSharp):
    1. [WorldSystemFilter(WorldSystemFilterFlags.Default | WorldSystemFilterFlags.Editor | WorldSystemFilterFlags.ThinClientSimulation, WorldSystemFilterFlags.Default)]
    2. public class BeforeLocalToWorldEntityCommandBufferSystem : EntityCommandBufferSystem
    3. {
    4.     public struct Singleton : IComponentData, IQueryTypeParameter, IECBSingleton
    5.     {
    6.         internal unsafe UnsafeList<EntityCommandBuffer>* pendingBuffers;
    7.  
    8.         internal Allocator allocator;
    9.  
    10.         public unsafe EntityCommandBuffer CreateCommandBuffer(WorldUnmanaged world)
    11.         {
    12.             return EntityCommandBufferSystem.CreateCommandBuffer(ref *pendingBuffers, allocator, world);
    13.         }
    14.  
    15.         public unsafe void SetPendingBufferList(ref UnsafeList<EntityCommandBuffer> buffers)
    16.         {
    17.             pendingBuffers = (UnsafeList<EntityCommandBuffer>*)UnsafeUtility.AddressOf(ref buffers);
    18.         }
    19.  
    20.         public void SetAllocator(Allocator allocatorIn)
    21.         {
    22.             allocator = allocatorIn;
    23.         }
    24.     }
    25.  
    26.     protected override void OnCreate()
    27.     {
    28.         base.OnCreate();
    29.         this.RegisterSingleton<Singleton>(ref base.PendingBuffers, base.World.Unmanaged, "BeforeLocalToWorldEntityCommandBufferSystem Singleton");
    30.     }
    31. }
    but it errors on line 29 accessing base.PendingBuffers, 'EntityCommandBufferSystem' does not contain definition for 'PendingBuffers'. What should be done to make it work?
     
  2. Anthiese

    Anthiese

    Joined:
    Oct 13, 2013
    Posts:
    72
    bb8_1 and Mayumichi like this.
  3. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,626
    -edit- beaten by seconds

    you can use m_PendingBuffers as it's marked protected. Example from my project

    Code (CSharp):
    1.     [UpdateInGroup(typeof(DestroySystemGroup), OrderLast = true)]
    2.     public unsafe class EndDestroyCommandBufferSystem : EntityCommandBufferSystem
    3.     {
    4.         public struct Singleton : IComponentData, IECBSingleton
    5.         {
    6.             private UnsafeList<EntityCommandBuffer>* pendingBuffers;
    7.             private Allocator allocator;
    8.  
    9.  
    10.             public EntityCommandBuffer CreateCommandBuffer(WorldUnmanaged world)
    11.             {
    12.                 return EntityCommandBufferSystem.CreateCommandBuffer(ref *this.pendingBuffers, this.allocator, world);
    13.             }
    14.  
    15.             public void SetPendingBufferList(ref UnsafeList<EntityCommandBuffer> buffers)
    16.             {
    17.                 this.pendingBuffers = (UnsafeList<EntityCommandBuffer>*)UnsafeUtility.AddressOf(ref buffers);
    18.             }
    19.  
    20.             public void SetAllocator(Allocator allocatorIn)
    21.             {
    22.                 this.allocator = allocatorIn;
    23.             }
    24.         }
    25.  
    26.  
    27.         protected override void OnCreate()
    28.         {
    29.             base.OnCreate();
    30.  
    31.             this.RegisterSingleton<Singleton>(ref *this.m_PendingBuffers, this.World.Unmanaged, $"{nameof(EndDestroyCommandBufferSystem)} {nameof(Singleton)}");
    32.         }
    33.     }
     
    bb8_1, Mayumichi and Anthiese like this.
  4. Mayumichi

    Mayumichi

    Joined:
    Mar 12, 2017
    Posts:
    31
    Awesome it works, thanks to both of you :)