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

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.NativeList1[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(NativeList1, Int32, AllocatorHandle) (at ./Library/PackageCache/com.unity.entities@1.0.11/Unity.Entities/World.cs:1288)
Unity.Entities.World:GetOrCreateSystemsAndLogException(NativeList1, AllocatorHandle) (at ./Library/PackageCache/com.unity.entities@1.0.11/Unity.Entities/World.cs:1348) Unity.Entities.DefaultWorldInitialization:AddSystemToRootLevelSystemGroupsInternal(World, NativeList1, 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?

Is it perhaps a generic isystem, and did you perhaps forget to [assembly: RegisterGenericSystem(typeof(YourSystem))]?

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?

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:

public partial class AddVisualEffectCleanupSystem : SystemBase
{
    private EndSimulationEntityCommandBufferSystem _commandBufferSystem;

    private EntityQuery _query;
   
    protected override void OnCreate()
    {
        _commandBufferSystem = World.GetOrCreateSystemManaged<EndSimulationEntityCommandBufferSystem>();

        _query = new EntityQueryBuilder(Allocator.Temp)
            .WithAll<VisualEffectMarker>()
            .WithNone<VisualEffectCleanup>().Build(this);
    }

    protected override void OnUpdate()
    {
        AddCleanupComponentJob addCleanupComponentJob = new()
        {
            EntityType = GetEntityTypeHandle(),
            MarkerType = GetComponentTypeHandle<VisualEffectMarker>(),
            CommandBuffer = _commandBufferSystem.CreateCommandBuffer().AsParallelWriter()
        };
        Dependency = addCleanupComponentJob.ScheduleParallel(_query, Dependency);

        _commandBufferSystem.AddJobHandleForProducer(Dependency);
    }

    [BurstCompile]
    private struct AddCleanupComponentJob : IJobChunk
    {
        [ReadOnly]
        public EntityTypeHandle EntityType;

        [ReadOnly]
        public ComponentTypeHandle<VisualEffectMarker> MarkerType;

        public EntityCommandBuffer.ParallelWriter CommandBuffer;

        public void Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
        {
            NativeArray<Entity> entities = chunk.GetNativeArray(EntityType);
            NativeArray<VisualEffectMarker> markers = chunk.GetNativeArray(ref MarkerType);

            ChunkEntityEnumerator enumerator = new(useEnabledMask, chunkEnabledMask, chunk.Count);
            while (enumerator.NextEntityIndex(out int i))
            {
                Entity entity = entities[i];
                VisualEffectMarker marker = markers[i];

                CommandBuffer.AddComponent(unfilteredChunkIndex, entity, new VisualEffectCleanup(marker.Id));
            }
        }
    }
}

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.

Sorry for the late reply. The system has been renamed. The old struct system looked like this as far as I can remember:

public partial struct AddCleanupComponentSystem : ISystem
{
    private EntityQuery _query;

    [BurstCompile]
    public void OnCreate(ref SystemState state)
    {
        _query = new EntityQueryBuilder(Allocator.Temp)
            .WithAll<VisualEffectMarker>()
            .WithAll<GuidComponentData>()
            .WithNone<VisualEffectCleanup>().Build(ref state);
    }

    public void OnDestroy(ref SystemState state)
    {
    }

    [BurstCompile]
    public void OnUpdate(ref SystemState state)
    {
        EndSimulationEntityCommandBufferSystem.Singleton commandBufferSystem =
            SystemAPI.GetSingleton<EndSimulationEntityCommandBufferSystem.Singleton>();

        AddCleanupComponentJob addCleanupComponentJob = new()
        {
            EntityType = state.GetEntityTypeHandle(),
            GuidType = state.GetComponentTypeHandle<GuidComponentData>(),
            CommandBuffer = commandBufferSystem.CreateCommandBuffer(state.WorldUnmanaged).AsParallelWriter()
        };
        state.Dependency = addCleanupComponentJob.ScheduleParallel(_query, state.Dependency);
    }

    [BurstCompile]
    private struct AddCleanupComponentJob : IJobChunk
    {
        [ReadOnly]
        public EntityTypeHandle EntityType;

        [ReadOnly]
        public ComponentTypeHandle<GuidComponentData> GuidType;

        public EntityCommandBuffer.ParallelWriter CommandBuffer;

        public void Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
        {
            NativeArray<Entity> entities = chunk.GetNativeArray(EntityType);
            NativeArray<GuidComponentData> guids = chunk.GetNativeArray(ref GuidType);

            ChunkEntityEnumerator enumerator = new(useEnabledMask, chunkEnabledMask, chunk.Count);
            while (enumerator.NextEntityIndex(out int i))
            {
                Entity entity = entities[i];
                GuidComponentData guid = guids[i];

                CommandBuffer.AddComponent(unfilteredChunkIndex, entity, new VisualEffectCleanup(guid.hashCode));
            }
        }
    }
}

I got the same error when build android apk. This is my code.

using System;
using ET;
using Unity.Burst;
using Unity.Collections;
using Unity.Entities;
using Unity.Mathematics;
using Unity.Transforms;
using UnityEngine;
using Entity = Unity.Entities.Entity;

namespace ECS
{
    [BurstCompile]
    public partial struct SpawnDamageNumSystem : ISystem
    {
        private EntityCommandBuffer m_Ecb;
        private DamageConfig configs;
       
        [BurstCompile]
        public void OnCreate(ref SystemState state)
        {
            state.RequireForUpdate<SpawnDamageNum>();
            state.RequireForUpdate<DamageConfig>();
        }
        [BurstCompile]
        public void OnUpdate(ref SystemState state)
        {
            var ecbSingleton = SystemAPI.GetSingleton<BeginSimulationEntityCommandBufferSystem.Singleton>();

            new SpawnDamageNumJob()
            {
                Ecb = ecbSingleton.CreateCommandBuffer(state.WorldUnmanaged).AsParallelWriter(),
                DamageConfig = SystemAPI.GetSingleton<DamageConfig>(),
                ElapsedTime = (float)SystemAPI.Time.ElapsedTime,
            }.ScheduleParallel();
        }
    }
   
    //[BurstCompile]
    public partial struct SpawnDamageNumJob : IJobEntity
    {
        public EntityCommandBuffer.ParallelWriter Ecb;
        public DamageConfig DamageConfig;
        [ReadOnly] public float ElapsedTime;

        public void Execute([ChunkIndexInQuery] int chunkIndex, Entity entity, in SpawnDamageNum damageNum)
        {
            long result = 0;
            float offset = 0;
            float fontWidth = this.DamageConfig.GetFontWidth(damageNum.Type);
            var transform = LocalTransform.FromPositionRotationScale(damageNum.Position, quaternion.identity, this.DamageConfig.GetBaseScale(damageNum.Type));
            if (damageNum.Number < 100000)
            {
                result = damageNum.Number;
                offset = math.log10(result) / 2 * fontWidth;
                transform.Position.x += offset;
            }
            else if (damageNum.Number < 100000000)//K
            {
                result = damageNum.Number / 1000;
                offset = math.log10(result*10f) / 2 * fontWidth;
                transform.Position.x += offset;
                Entity prefab = DamageConfig.GetNumberPrefab(damageNum.Type, DamageChar.K);
                Entity ne = this.Ecb.Instantiate(chunkIndex, prefab);
                this.Ecb.SetComponent(chunkIndex, ne, transform);
                transform.Position.x -= fontWidth;
                transform.Position.z -= 0.0001f;
                this.Ecb.AddComponent(chunkIndex, ne, new MoveData()
                {
                    MoveTime = DamageConfig.GetLifeTime(damageNum.Type),
                    SpawnTime = ElapsedTime,
                    OriginalScale = this.DamageConfig.GetBaseScale(damageNum.Type),
                    OriginalY = transform.Position.y,
                    ScaleOffset = this.DamageConfig.GetScaleOffset(damageNum.Type),
                    VerticalOffset = this.DamageConfig.GetVerticalOffset(damageNum.Type),
                });
            }
            else if (damageNum.Number < 100000000000)//M
            {
                result = damageNum.Number / 1000000;
                offset = math.log10(result*10f) / 2 * fontWidth;
                transform.Position.x += offset;
                Entity prefab = DamageConfig.GetNumberPrefab(damageNum.Type, DamageChar.M);
                Entity ne = this.Ecb.Instantiate(chunkIndex, prefab);
                this.Ecb.SetComponent(chunkIndex, ne, transform);
                transform.Position.x -= fontWidth;
                transform.Position.z -= 0.0001f;
                this.Ecb.AddComponent(chunkIndex, ne, new MoveData()
                {
                    MoveTime = DamageConfig.GetLifeTime(damageNum.Type),
                    SpawnTime = ElapsedTime,
                    OriginalScale = this.DamageConfig.GetBaseScale(damageNum.Type),
                    OriginalY = transform.Position.y,
                    ScaleOffset = this.DamageConfig.GetScaleOffset(damageNum.Type),
                    VerticalOffset = this.DamageConfig.GetVerticalOffset(damageNum.Type),
                });
            }
            else//B
            {
                result = damageNum.Number / 1000000000;
                offset = math.log10(result * 10f) / 2 * fontWidth;
                transform.Position.x += offset;
                Entity prefab = DamageConfig.GetNumberPrefab(damageNum.Type, DamageChar.B);
                Entity ne = this.Ecb.Instantiate(chunkIndex, prefab);
                this.Ecb.SetComponent(chunkIndex, ne, transform);
                transform.Position.x -= fontWidth;
                transform.Position.z -= 0.0001f;
                this.Ecb.AddComponent(chunkIndex, ne, new MoveData()
                {
                    MoveTime = DamageConfig.GetLifeTime(damageNum.Type),
                    SpawnTime = ElapsedTime,
                    OriginalScale = this.DamageConfig.GetBaseScale(damageNum.Type),
                    OriginalY = transform.Position.y,
                    ScaleOffset = this.DamageConfig.GetScaleOffset(damageNum.Type),
                    VerticalOffset = this.DamageConfig.GetVerticalOffset(damageNum.Type),
                });
            }

            while (result > 0)
            {
                var digit = result % 10;
                result /= 10;
                Entity prefab = DamageConfig.GetNumberPrefab(damageNum.Type, digit);
                Entity ne = this.Ecb.Instantiate(chunkIndex, prefab);
                this.Ecb.SetComponent(chunkIndex, ne, transform);
                transform.Position.x -= fontWidth;
                transform.Position.z -= 0.0001f;
                this.Ecb.AddComponent(chunkIndex, ne, new MoveData()
                {
                    MoveTime = DamageConfig.GetLifeTime(damageNum.Type),
                    SpawnTime = ElapsedTime,
                    OriginalScale = this.DamageConfig.GetBaseScale(damageNum.Type),
                    OriginalY = transform.Position.y,
                    ScaleOffset = this.DamageConfig.GetScaleOffset(damageNum.Type),
                    VerticalOffset = this.DamageConfig.GetVerticalOffset(damageNum.Type),
                });
            }
           
            Ecb.DestroyEntity(chunkIndex, entity);
        }
    }
}