Hey, so I have my GameInstance and a custom class. I spawn my custom class, and I then let my game instance know about the new object:
UPROPERTY(BlueprintReadWrite)
UWSSpawnItems* ItemSpawner;
GameInst = Cast<UWSGameInstance>(UGameplayStatics::GetGameInstance(GetWorld()));
ItemSpawner = NewObject<UWSSpawnItems>();
ItemSpawner->Init();
GameInst->ItemSpawner = ItemSpawner;
If I print ItemSpawner from my gameInst, it works fine, giving me the object in question:
(However, I noticed that it spawns an additional one each time I start the game in editor? Shouldn’t the game instance reset?)
But as soon as I try to make use of it:
if (IsValid(ItemSpawner))
{
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Green, FString("New Loadout unlocked!"));
}
It crashes with a “**this** was nullptr
”
Even IsValid or != nullptr isn’t safe somehow?