Search Unity

CommandBuffer Warnings Spamming the Console after upgrading to SystemBase

Discussion in 'Entity Component System' started by Opeth001, May 12, 2020.

  1. Opeth001

    Opeth001

    Joined:
    Jan 28, 2017
    Posts:
    1,117
    Hello Everyone,

    i updated my JobComponentSystem to SystemBase and changed related Code.

    Code (CSharp):
    1. #if ECS_CODE
    2. using CWBR.Client.Systems;
    3. using CWBR.ClientAndServer.Components;
    4. using CWBR.ClientAndServer.Constants;
    5. using Unity.Burst;
    6. using Unity.Collections;
    7. using Unity.Entities;
    8. using Unity.Jobs;
    9. using Unity.Mathematics;
    10. using UnityEngine;
    11. using Utils._Math;
    12.  
    13. namespace CWBR.ClientAndServer.Systems
    14. {
    15.  
    16.  
    17.     [UpdateInGroup(typeof(InitializationSystemGroup))]
    18.     [UpdateBefore(typeof(ProjectileSpawnerSystem))]
    19.     [UpdateAfter(typeof(LocalPlayerInputTesting))] //TODO: Remove this line for Production (LocalPlayerInputTesting is just for testing)
    20.     public class FiringSystem : SystemBase
    21.     {
    22.         EndSimulationEntityCommandBufferSystem m_EntityCommandBufferSystem;
    23.         protected override void OnCreate()
    24.         {
    25.             m_EntityCommandBufferSystem = World.GetOrCreateSystem<EndSimulationEntityCommandBufferSystem>();
    26.         }
    27.        
    28.         protected override void OnUpdate()
    29.         {
    30.             var commandBuffer = m_EntityCommandBufferSystem.CreateCommandBuffer();
    31.  
    32.            
    33.             // Remove Firing Tag From Non Shooting Players
    34.             Entities
    35.                .WithAll<FiringTag>()
    36.                .ForEach((Entity entity, in AimInput aimInput) => {
    37.                    // Player is pushing Joystick enought to shoot
    38.                    if (math.distance(float2.zero, aimInput.Value) - GameParams.PlayerDefaultMinimumJoystickPushToShoot < _MathUtils.Epsilon)
    39.                        commandBuffer.RemoveComponent<FiringTag>(entity);
    40.                }).Run();
    41.  
    42.  
    43.  
    44.             var deltaTime = Time.DeltaTime;
    45.             // Manage CoolDown for Non Shooting Players
    46.             // Add Firing Tag To Shooting players
    47.             Entities
    48.                 .WithAll<AliveTag>()
    49.                 .WithAll<PlayerId>()
    50.                 .WithNone<FiringTag>()
    51.                 .ForEach((Entity entity, ref FiringCooldown firingCooldown, in AimInput aimInput) => {
    52.  
    53.                     // Player is pushing Joystick enought to shoot
    54.                     if (math.distance(float2.zero, aimInput.Value) - GameParams.PlayerDefaultMinimumJoystickPushToShoot > _MathUtils.Epsilon)
    55.                         commandBuffer.AddComponent(entity, new FiringTag { });
    56.  
    57.                     // Reset CoolDown in case user started shooting again and his not already waiting for another cooldown to complete
    58.                     if (firingCooldown.CoolDown - GameParams.PlayerDefaultFiringCoolDown < _MathUtils.Epsilon)
    59.                         firingCooldown.CoolDown = GameParams.PlayerDefaultFiringCoolDown;
    60.                     else
    61.                         firingCooldown.CoolDown -= deltaTime;
    62.                 }).Run();
    63.  
    64.            
    65.         }
    66.     }
    67. }
    68. #endif
    the Console is spammed by this Warining:
    Code (CSharp):
    1. Internal: deleting an allocation that is older than its permitted lifetime of 4 frames (age = 8)
    2. Unity.Collections.LowLevel.Unsafe.UnsafeUtility:Free(Void*, Allocator)
    3. Unity.Entities.EntityCommandBuffer:Dispose() (at Packages/com.unity.entities@0.10.0-preview.6/Unity.Entities/EntityCommandBuffer.cs:1017)
    4. Unity.Entities.EntityCommandBufferSystem:FlushPendingBuffers(Boolean) (at Packages/com.unity.entities@0.10.0-preview.6/Unity.Entities/EntityCommandBufferSystem.cs:249)
    5. Unity.Entities.EntityCommandBufferSystem:OnUpdate() (at Packages/com.unity.entities@0.10.0-preview.6/Unity.Entities/EntityCommandBufferSystem.cs:188)
    6. Unity.Entities.ComponentSystem:Update() (at Packages/com.unity.entities@0.10.0-preview.6/Unity.Entities/ComponentSystem.cs:109)
    7. Unity.Entities.ComponentSystemGroup:UpdateAllSystems() (at Packages/com.unity.entities@0.10.0-preview.6/Unity.Entities/ComponentSystemGroup.cs:240)
    8. Unity.Entities.ComponentSystemGroup:OnUpdate() (at Packages/com.unity.entities@0.10.0-preview.6/Unity.Entities/ComponentSystemGroup.cs:219)
    9. Unity.Entities.ComponentSystem:Update() (at Packages/com.unity.entities@0.10.0-preview.6/Unity.Entities/ComponentSystem.cs:109)
    10. Unity.Entities.DummyDelegateWrapper:TriggerUpdate() (at Packages/com.unity.entities@0.10.0-preview.6/Unity.Entities/ScriptBehaviourUpdateOrder.cs:196)
    11.  
     
  2. agurskis22cans

    agurskis22cans

    Joined:
    Jul 17, 2019
    Posts:
    9
    I'm not 100% sure, but try using separate ECBs for different jobs.
     
    Opeth001 likes this.
  3. Opeth001

    Opeth001

    Joined:
    Jan 28, 2017
    Posts:
    1,117
    this is not working :/
     
  4. WAYNGames

    WAYNGames

    Joined:
    Mar 16, 2019
    Posts:
    992
    Don't you have to setup up the playback of the command buffer after running your foreach ?
    Like we did befor with the ecbSystem.addJobHandleForProducer() method ?
     
  5. Opeth001

    Opeth001

    Joined:
    Jan 28, 2017
    Posts:
    1,117
    I'm not sure but I think the PlayBack() function has a different utility than the addJobHandleForProducer().
    From what I know, PlayBack() will use the EntityManager to execute all commands at the end of the system instead of using the existing barriers. this way Extra Sync points will be created.
     
  6. Opeth001

    Opeth001

    Joined:
    Jan 28, 2017
    Posts:
    1,117
    Note: the command buffer is working correctly (Removing/Adding components)
    but the spamming warnings are slowing the Game.
     
  7. Opeth001

    Opeth001

    Joined:
    Jan 28, 2017
    Posts:
    1,117
    i found it! :)
    i was using the EndSimulationEntityCommandBufferSystem inside a System running within the InitializationSystemGroup.