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

NetCube Example : CubeInput Runnning on depreciated system.

Discussion in 'Entity Component System' started by RyancHaynes, Aug 12, 2020.

  1. RyancHaynes

    RyancHaynes

    Joined:
    Dec 8, 2018
    Posts:
    11
    Assuming we inherit the new implementation SystemBase, what would be the replacement for?
    PostUpdateCommands.AddBuffer
    &
    PostUpdateCommands.SetComponent
     
  2. RyancHaynes

    RyancHaynes

    Joined:
    Dec 8, 2018
    Posts:
    11
    Solution: Create A Job.WithCode to shcedule your task (rather than entity command buffer )
    Add the buffer the the entity via the EntityManager, Add Component of the typeof you desire.
    Job.WithCode(() =>
    {
    EntityManager.AddBuffer<Type>(ent);

    //Component type is implicitly Read Write.
    EntityManager.AddComponent(ent, typeof(ComponentType));

    }).Schedule();
     
  3. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,627
    The actual solution to replicate the behaviour is to simply create the buffer yourself.

    Code (CSharp):
    1. var PostUpdateCommands = new EntityCommandBuffer(Allocator.TempJob);
    2.  
    3. PostUpdateCommands.AddBuffer
    4. PostUpdateCommands.SetComponent
    5.  
    6. PostUpdateCommands.PlayBack(EntityManager);
    7. PostUpdateCommands.Dispose();
     
    Lukas_Kastern likes this.
  4. RyancHaynes

    RyancHaynes

    Joined:
    Dec 8, 2018
    Posts:
    11
    Assuming I'm running in the default World, is there not a more effective way to get a handle on an EntityCommandBuffer? As creating a new one would also create a new synch point as well correct? I guess my question is if there's an ECB instantiated anywhere already in the architecture?

    I don't imagine I should create this in an Entity.ForEach()
     
    Last edited: Aug 13, 2020
  5. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,627
    Yes it will create a sync point, but that is exactly what PostUpdateCommands did and I was simply replicating the behaviour (EntityManager).

    If you want to avoid sync points you need to use a buffer system to defer the sync point till later.
     
    RyancHaynes likes this.