Hello Everyone,
I’m currently working on streamlining my Ability System framework by consolidating repetitive code commonly used across various systems. This includes tasks like declaring, initializing, and updating lookups, as well as accessing certain singletons that use doesn’t even have to know about.
However, I’ve encountered an issue: it appears that using SystemAPI methods, such as GetSingleton, is restricted outside of Systems.
Error: EA0004: You may not use the SystemAPI member GetSingleton
outside of a system. SystemAPI members rely on setup from the containing system.
public struct AbilitySystemContext
{
[ReadOnly] public GameplayActionsFunctionsPointersSingleton GameplayActionsFunctionsPointersSingleton;
[ReadOnly] public AbilityResourcesSingleton AbilityResourcesSingleton;
[ReadOnly] public BufferLookup<ActorGameplayAttributes> ActorGameplayAttributesLookup;
[ReadOnly] public ComponentLookup<ActorGameplayTags> ActorGameplayTagsLookup;
[ReadOnly] public ComponentLookup<AbilityInstanceDefinition> AbilityInstanceDefinitionLookup;
[ReadOnly] public EntityStorageInfoLookup EntityStorageInfoLookup;
public void OnCreate(ref SystemState state)
{
//Declare the Requirements for the Implementing System
state.RequireForUpdate<GameplayActionsFunctionsPointersSingleton>();
state.RequireForUpdate<AbilityResourcesSingleton>();
//Initialize the Component Lookups
ActorGameplayAttributesLookup = state.GetBufferLookup<ActorGameplayAttributes>(true);
ActorGameplayTagsLookup = state.GetComponentLookup<ActorGameplayTags>(true);
AbilityInstanceDefinitionLookup = state.GetComponentLookup<AbilityInstanceDefinition>(true);
EntityStorageInfoLookup = state.GetEntityStorageInfoLookup();
}
public void OnUpdate(ref SystemState state)
{
//Update Components Lookups
ActorGameplayAttributesLookup.Update(ref state);
ActorGameplayTagsLookup.Update(ref state);
AbilityInstanceDefinitionLookup.Update(ref state);
EntityStorageInfoLookup = state.GetEntityStorageInfoLookup();
GameplayActionsFunctionsPointersSingleton = SystemAPI.GetSingleton<GameplayActionsFunctionsPointersSingleton>();
AbilityResourcesSingleton = SystemAPI.GetSingleton<AbilityResourcesSingleton>();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public BlobAssetReference<GameplayAbilityDefinition> GetAbilityDefinition(Entity abilityInstance) =>
this.AbilityInstanceDefinitionLookup[abilityInstance].AbilityDefinition;
}
Does anyone know of a hidden API or a workaround that could help me bypass this limitation?
Any suggestions would be greatly appreciated.