x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

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

Product Version: UE 4.22
Tags:
more ▼

asked Apr 22 '19 at 05:02 PM in C++ Programming

avatar image

Aszura
6 1 2

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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...

more ▼

answered May 02 '19 at 04:49 AM

avatar image

Enderderder
6 1 3

avatar image Aszura May 07 '19 at 06:54 AM

Thank you! It helps me a lot to know that I'm not the only one ;) 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!

avatar image Enderderder May 07 '19 at 07:54 AM

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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question