How To Generic ISystem<Component>?

How does one overcome this error:

ArgumentException: Unknown Type:`ECS.Systems.EffectTriggerSystem`1[ECS.Components.Effects.EffectSpeed]` All ComponentType must be known at compile time. For generic components, each concrete type must be registered with [RegisterGenericComponentType].

in:

fixedStepSimulation.AddSystemToUpdateList(_world.CreateSystem<EffectTriggerSystem<EffectSpeed>>());

where system:

public partial struct EffectTriggerSystem<T> : ISystem where T: unmanaged, IEffectTimed

where component:

public struct EffectSpeed : IEffectTimed

where interface:public interface IEffect : IComponentData, IEnableableComponent

If I use this generic in EntityMamanger, like em.GetComponentData(entity) - it works just fine, but throws when I try to use generic ISystem.

[assembly: RegisterGenericComponentType(typeof(EffectTriggerSystem<EffectSpeed>))]

has no effect.

Generic isystems don’t work right now; it’s on the todo.

4 Likes

You can try a generic SystemBase for now. It worked in 0.50. Not sure if it works on 1.0. I’m still in the process of upgrading my project.

Atm. one of work around, but far from ideal as I have experienced, is to tap into System state of ISystem.

Edit: Sorry, code posted was not really generic. Removed.

Does SystemBase work?

Yes :slight_smile:

1 Like

I made generic isystems work in 1.0.8, so enjoy! (Edit: you have to say [assembly: RegisterGenericSystemType(typeof(YourSystem))], just like for generic components.)

16 Likes

Generic IJobEntity soon so ? :smile:

Mmm that’s harder. I’m skeptical personally, but you never know. The people who could do that (i.e. the sourcegenerator people) are currently hard at work trying to bring iteration time down, which I suspect you might prefer…?

4 Likes

Um, due to internal process snafus, this apparently did not make it into 1.0.8. Sorry for the confusion! I’m trying to figure out what release it will end up in. :frowning:

5 Likes

In 1.0.10 I’m trying to use RegisterGenericSystemType like this

[assembly: RegisterGenericSystemType(typeof(MySystem))]

And this gives me an error:

Unity.Entities.CodeGen.EntitiesILPostProcessors: (0,0): error error DC3002: MySystem: [RegisterGenericJobType] requires an instance of a generic value type

But I don’t have any generic job types

Is your system generic? Like MySystem? Then you also need to declare that in the typeof.
If not, you just need to register the generic job and not the system.

I have this classes:

public abstract partial MyBaseSystem<T> : SystemBase

public partial MyGameSystem : MyBaseSystem<GameState>

And I have tried both

[assembly: RegisterGenericSystemType(typeof(MyBaseSystem<GameState>))]
[assembly: RegisterGenericSystemType(typeof(MyGameSystem))]

I don’t have any generic jobs

RegisterGenericSystemType is only needed for ISystem.
SystemBase just needs an implementation and will work.

but if I remove RegisterGenericSystemType I get another error when calling AddSystemManaged:

ArgumentException: Unknown Type:`MyGameSystem` All ComponentType must be known at compile time. For generic components, each concrete type must be registered with [RegisterGenericComponentType].

Hm, that’s odd that this is thrown.
I have [DisableAutoCreation] on the base class. When implemented, the system is automatically added so I never need to call AddSystemManaged.

I confirm that this code now doens’t work

 [DisableAutoCreation]
    public partial class RenderingDOTSPositionSyncEngine:SystemBase
{
}

world.AddSystemManaged(new RenderingDOTSPositionSyncEngine());

that’s because RenderingDOTSPositionSyncEngine is not found inside the TypeManager stuff and AddSystemManaged now checks for it. I couldn’t find a work around yet.

Do we also need to specify RegisterGenericSystemType for managed generic systems?

Any updates on this?