UE 4.22 Subsystems - error when calling GetSubsystemArray()

Hi!

I’m currently trying to implement the new subsystems introduced in UE 4.22.

I have created a UGameplayBaseSubsystem class that inherits UGameInstanceSubsystem. Now I want to get the array with all subsystems of type UGameplayBaseSubsystem from my UGameInstance. Fortunately, there is a convenient method for that.

Problem:
However, when I try to call UGameInstance::GetSubsystemArray(), I get the following compile error:

c:\program files\epic games\ue_4.22\engine\source\runtime\engine\public\Subsystems/SubsystemCollection.h(94): error C2440: 'reinterpret_cast': cannot convert from 'const TArray<USubsystem *,FDefaultAllocator> *' to 'TArray<UGameInstanceSubsystem *,FDefaultAllocator> *'
c:\program files\epic games\ue_4.22\engine\source\runtime\engine\public\Subsystems/SubsystemCollection.h(94): note: Conversion loses qualifiers
C:\Program Files\Epic Games\UE_4.22\Engine\Source\Runtime\Engine\Classes\Engine/GameInstance.h(349): note: see reference to function template instantiation 'const TArray<UGameInstanceSubsystem *,FDefaultAllocator> &FSubsystemCollection<UGameInstanceSubsystem>::GetSubsystemArray<TSubsystemClass>(TSubclassOf<UGameInstanceSubsystem>) const' being compiled
        with
        [
            TSubsystemClass=UGameInstanceSubsystem
        ]
C:\Program Files\Epic Games\UE_4.22\Engine\Source\Runtime\Engine\Classes\Engine/GameInstance.h(349): note: see reference to function template instantiation 'const TArray<UGameInstanceSubsystem *,FDefaultAllocator> &FSubsystemCollection<UGameInstanceSubsystem>::GetSubsystemArray<TSubsystemClass>(TSubclassOf<UGameInstanceSubsystem>) const' being compiled
        with
        [
            TSubsystemClass=UGameInstanceSubsystem
        ]
C:\Users\Simon\Documents\Unreal Projects\HeroColony\Source\HeroColony\HeroColonyGameInstance.cpp(9): note: see reference to function template instantiation 'const TArray<UGameInstanceSubsystem *,FDefaultAllocator> &UGameInstance::GetSubsystemArray<UGameInstanceSubsystem>(void) const' being compiled

I guess the problem here are missing const specifiers for SpecificArray in FSubsystemCollection::GetSubsystemArray():

const TArray<USubsystem*>& Array = GetSubsystemArrayInternal(SubsystemBaseClass);
TArray<TSubsystemClass*>* SpecificArray = reinterpret_cast<TArray<TSubsystemClass*>*>(&Array);

Adding the two const specifiers makes the code compile just fine:

const TArray<TSubsystemClass*>* SpecificArray = reinterpret_cast<const TArray<TSubsystemClass*>*>(&Array);

My question(s):
Any idea how to resolve this without rewriting the engine code?

Did I miss something or did someone run into the same problem?
Has there been a bug report for this?

BR, Simon

I’m having the same issue. Not sure if Unreal Devs notice it. Currently I’ll just manually call them one by one using each type that I defined and then put them into an array. It is pretty annoying…

Thank you! It helps me a lot to know that I’m not the only one :wink:
I also thought about calling them one by one, but for now I’ve switched to actors, since in my case it’s only a prototype with one map.
If possible, I’ll try to report this as a bug!

Np XD. This new system is great, but imo they still needs a lot of work. The functionality is very limited. Hope it will be great in the future.