Hi, I’ve created a GameInstance Subsystem to create an Actor Container (to controll all Actors in my scene, be able to do search between them and pawns, etc.). I created a Game Instance Subsystem C++ class based on UGameInstanceSubsystem. The subsystem seems to create correctly, and can call functions from Actors to the Subsystem (I did a function that just logs out a text, and works properly).
The problem is that in the Subsystem, I cannot create variables, pointers, TArrays… When I create them, the compile process will success (via Live Coding), but when execute the game, the engine crash…
You know what can cause those problems?
Here’s the code:
.h:
#include “CoreMinimal.h”
#include “Subsystems/GameInstanceSubsystem.h”
#include “GeneralContainer_GISubsystem.generated.h”
UCLASS()
class HTN_PLANNIG_UE5_VE_API UGeneralContainer_GISubsystem : public UGameInstanceSubsystem
{
GENERATED_BODY()
public:
virtual void Initialize(FSubsystemCollectionBase& Collection) override;
virtual void Deinitialize() override;
public:
void PrintTest();
// class RandomClass* random; // this will crash the engine
// int a; // this will crash the engine
};
And the .cpp:
#include “Subsystems/GeneralContainer/GeneralContainer_GISubsystem.h”
#include “GeneralProjectContainer/GeneralProjectContainer.h”
void UGeneralContainer_GISubsystem::Initialize(FSubsystemCollectionBase& Collection)
{
Super::Initialize(Collection);
UE_LOG(LogTemp, Display, TEXT(“General Container Game Instance Subsystem initialized!”));
}
void UGeneralContainer_GISubsystem::Deinitialize()
{
Super::Deinitialize();
}
void UGeneralContainer_GISubsystem::PrintTest()
{
UE_LOG(LogTemp, Display, TEXT(“General Container Game Instance Subsystem Printed done!”));
}
Both logs are printed.
Note: I didn’t make any modification in the editor, and in any other C++ file.
Note2: I’m using Unreal Engine 5.1
Note after fixing the problem: If I compile from VS with Engine closed without adding any variable, the problem persisted when I created one. But, if I first create the variable, then close Engine, ReBuild from VS, then worked.
At the end I maintained a class independently, and the subsystem just have a pointer to that class.
Thanks!