When returning nullptr my UE4 crashes. I’m trying to make a saving function and when the save text is nothing it checks whether it is valid and then returns the nullptr value instead of the cast. How is returning null meant to be done in c++? I think my practices are different because my main language before c++ was Java. Here is what some of the code looks like in my .cpp:
USG_Evolution* UCFunctionLibrary::SGUserSave(FString SaveName, FString& SaveNameReturn)
{
SaveNameReturn = SaveName;
TSubclassOf<USG_Evolution> Class;
USG_Evolution* SaveGameInstance = Cast<USG_Evolution>(SGBase(Class, SaveName, SaveNameReturn));
if (SaveGameInstance->IsValidLowLevel())
{
return SaveGameInstance;
}
else
{
UE_LOG(LogTemp, Log, TEXT("SGUserSave Failed"));
return nullptr;
}
}
So if the SaveGameInstance is valid it returns, otherwise it returns nullptr.