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

Bug couldn't be found in the SystemRegistry. (This is likely a bug in an ILPostprocessor.)

Discussion in 'Entity Component System' started by davenirline, Aug 2, 2023.

  1. davenirline

    davenirline

    Joined:
    Jul 7, 2010
    Posts:
    943
    I suddenly got this error after making a new ISystem. It's nothing special. It just adds a cleanup component to entities in its query that doesn't have that cleanup component yet.

    ArgumentException: Type Assets.Code.ECS.Systems.AddCleanupComponentSystem couldn't be found in the SystemRegistry. (This is likely a bug in an ILPostprocessor.)
    Unity.Entities.WorldUnmanagedImpl.CreateUnmanagedSystemInternal (Unity.Entities.World self, System.Int32 structSize, System.Int64 typeHash, System.Int32 typeIndex, System.Void*& systemPtr, System.Boolean callOnCreate) (at ./Library/PackageCache/com.unity.entities@1.0.11/Unity.Entities/WorldUnmanaged.cs:469)
    Unity.Entities.WorldUnmanagedImpl.CreateUnmanagedSystem (Unity.Entities.SystemTypeIndex t, System.Int64 typeHash, System.Boolean callOnCreate) (at ./Library/PackageCache/com.unity.entities@1.0.11/Unity.Entities/WorldUnmanaged.cs:596)
    Unity.Entities.WorldUnmanagedImpl.CreateUnmanagedSystem (Unity.Entities.SystemTypeIndex t, System.Boolean callOnCreate) (at ./Library/PackageCache/com.unity.entities@1.0.11/Unity.Entities/WorldUnmanaged.cs:677)
    Unity.Entities.WorldUnmanaged.CreateUnmanagedSystem (Unity.Entities.SystemTypeIndex unmanagedType, System.Boolean callOnCreate) (at ./Library/PackageCache/com.unity.entities@1.0.11/Unity.Entities/WorldUnmanaged.cs:1109)
    Unity.Entities.World.GetOrCreateSystemsAndLogException (Unity.Collections.NativeList`1[T] types, System.Int32 typesCount, Unity.Collections.AllocatorManager+AllocatorHandle allocator) (at ./Library/PackageCache/com.unity.entities@1.0.11/Unity.Entities/World.cs:1256)
    UnityEngine.Debug:LogException(Exception)
    Unity.Debug:LogException(Exception) (at ./Library/PackageCache/com.unity.entities@1.0.11/Unity.Entities/Stubs/Unity/Debug.cs:19)
    Unity.Entities.World:GetOrCreateSystemsAndLogException(NativeList`1, Int32, AllocatorHandle) (at ./Library/PackageCache/com.unity.entities@1.0.11/Unity.Entities/World.cs:1288)
    Unity.Entities.World:GetOrCreateSystemsAndLogException(NativeList`1, AllocatorHandle) (at ./Library/PackageCache/com.unity.entities@1.0.11/Unity.Entities/World.cs:1348)
    Unity.Entities.DefaultWorldInitialization:AddSystemToRootLevelSystemGroupsInternal(World, NativeList`1, ComponentSystemGroup, DefaultRootGroups) (at ./Library/PackageCache/com.unity.entities@1.0.11/Unity.Entities/DefaultWorldInitialization.cs:261)
    Unity.Entities.DefaultWorldInitialization:AddSystemToRootLevelSystemGroupsInternal(World, NativeList`1) (at ./Library/PackageCache/com.unity.entities@1.0.11/Unity.Entities/DefaultWorldInitialization.cs:300)
    Unity.Entities.DefaultWorldInitialization:Initialize(String, Boolean) (at ./Library/PackageCache/com.unity.entities@1.0.11/Unity.Entities/DefaultWorldInitialization.cs:153)
    Unity.Entities.AutomaticWorldBootstrap:Initialize() (at ./Library/PackageCache/com.unity.entities@1.0.11/Unity.Entities.Hybrid/Injection/AutomaticWorldBootstrap.cs:16)

    Why is this happening and what's the workaround?
     
  2. elliotc-unity

    elliotc-unity

    Unity Technologies

    Joined:
    Nov 5, 2015
    Posts:
    228
    Is it perhaps a generic isystem, and did you perhaps forget to [assembly: RegisterGenericSystem(typeof(YourSystem<YourParticularT>))]?

    If so, I agree the error message is bad and should be extended to suggest this. But if not, maybe paste the system to help us know more?
     
  3. davenirline

    davenirline

    Joined:
    Jul 7, 2010
    Posts:
    943
    It's not a generic system. The fix was to turn it into a class extending from SystemBase. I don't have the struct version anymore but turning this back to an ISystem is not hard:
    Code (CSharp):
    1. public partial class AddVisualEffectCleanupSystem : SystemBase
    2. {
    3.     private EndSimulationEntityCommandBufferSystem _commandBufferSystem;
    4.  
    5.     private EntityQuery _query;
    6.    
    7.     protected override void OnCreate()
    8.     {
    9.         _commandBufferSystem = World.GetOrCreateSystemManaged<EndSimulationEntityCommandBufferSystem>();
    10.  
    11.         _query = new EntityQueryBuilder(Allocator.Temp)
    12.             .WithAll<VisualEffectMarker>()
    13.             .WithNone<VisualEffectCleanup>().Build(this);
    14.     }
    15.  
    16.     protected override void OnUpdate()
    17.     {
    18.         AddCleanupComponentJob addCleanupComponentJob = new()
    19.         {
    20.             EntityType = GetEntityTypeHandle(),
    21.             MarkerType = GetComponentTypeHandle<VisualEffectMarker>(),
    22.             CommandBuffer = _commandBufferSystem.CreateCommandBuffer().AsParallelWriter()
    23.         };
    24.         Dependency = addCleanupComponentJob.ScheduleParallel(_query, Dependency);
    25.  
    26.         _commandBufferSystem.AddJobHandleForProducer(Dependency);
    27.     }
    28.  
    29.     [BurstCompile]
    30.     private struct AddCleanupComponentJob : IJobChunk
    31.     {
    32.         [ReadOnly]
    33.         public EntityTypeHandle EntityType;
    34.  
    35.         [ReadOnly]
    36.         public ComponentTypeHandle<VisualEffectMarker> MarkerType;
    37.  
    38.         public EntityCommandBuffer.ParallelWriter CommandBuffer;
    39.  
    40.         public void Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
    41.         {
    42.             NativeArray<Entity> entities = chunk.GetNativeArray(EntityType);
    43.             NativeArray<VisualEffectMarker> markers = chunk.GetNativeArray(ref MarkerType);
    44.  
    45.             ChunkEntityEnumerator enumerator = new(useEnabledMask, chunkEnabledMask, chunk.Count);
    46.             while (enumerator.NextEntityIndex(out int i))
    47.             {
    48.                 Entity entity = entities[i];
    49.                 VisualEffectMarker marker = markers[i];
    50.  
    51.                 CommandBuffer.AddComponent(unfilteredChunkIndex, entity, new VisualEffectCleanup(marker.Id));
    52.             }
    53.         }
    54.     }
    55. }
     
  4. elliotc-unity

    elliotc-unity

    Unity Technologies

    Joined:
    Nov 5, 2015
    Posts:
    228
    I'd need to see the actual ISystem that caused the error to be helpful here. The system you posted is not even named the same as the one in the error message, and makes it hard to know what it would have looked like.
     
  5. davenirline

    davenirline

    Joined:
    Jul 7, 2010
    Posts:
    943
    Sorry for the late reply. The system has been renamed. The old struct system looked like this as far as I can remember:
    Code (CSharp):
    1. public partial struct AddCleanupComponentSystem : ISystem
    2. {
    3.     private EntityQuery _query;
    4.  
    5.     [BurstCompile]
    6.     public void OnCreate(ref SystemState state)
    7.     {
    8.         _query = new EntityQueryBuilder(Allocator.Temp)
    9.             .WithAll<VisualEffectMarker>()
    10.             .WithAll<GuidComponentData>()
    11.             .WithNone<VisualEffectCleanup>().Build(ref state);
    12.     }
    13.  
    14.     public void OnDestroy(ref SystemState state)
    15.     {
    16.     }
    17.  
    18.     [BurstCompile]
    19.     public void OnUpdate(ref SystemState state)
    20.     {
    21.         EndSimulationEntityCommandBufferSystem.Singleton commandBufferSystem =
    22.             SystemAPI.GetSingleton<EndSimulationEntityCommandBufferSystem.Singleton>();
    23.  
    24.         AddCleanupComponentJob addCleanupComponentJob = new()
    25.         {
    26.             EntityType = state.GetEntityTypeHandle(),
    27.             GuidType = state.GetComponentTypeHandle<GuidComponentData>(),
    28.             CommandBuffer = commandBufferSystem.CreateCommandBuffer(state.WorldUnmanaged).AsParallelWriter()
    29.         };
    30.         state.Dependency = addCleanupComponentJob.ScheduleParallel(_query, state.Dependency);
    31.     }
    32.  
    33.     [BurstCompile]
    34.     private struct AddCleanupComponentJob : IJobChunk
    35.     {
    36.         [ReadOnly]
    37.         public EntityTypeHandle EntityType;
    38.  
    39.         [ReadOnly]
    40.         public ComponentTypeHandle<GuidComponentData> GuidType;
    41.  
    42.         public EntityCommandBuffer.ParallelWriter CommandBuffer;
    43.  
    44.         public void Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
    45.         {
    46.             NativeArray<Entity> entities = chunk.GetNativeArray(EntityType);
    47.             NativeArray<GuidComponentData> guids = chunk.GetNativeArray(ref GuidType);
    48.  
    49.             ChunkEntityEnumerator enumerator = new(useEnabledMask, chunkEnabledMask, chunk.Count);
    50.             while (enumerator.NextEntityIndex(out int i))
    51.             {
    52.                 Entity entity = entities[i];
    53.                 GuidComponentData guid = guids[i];
    54.  
    55.                 CommandBuffer.AddComponent(unfilteredChunkIndex, entity, new VisualEffectCleanup(guid.hashCode));
    56.             }
    57.         }
    58.     }
    59. }