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