Crash when returning nullptr for function

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.

Hey -

You can try setting another variable to null and then return that variable, however I get the feeling this may not work either. Can you provide information about the crash itself? The callstack and log files will help identify the crash, and if you could provide reproduction/setup steps, it will help me investigate the issue on my end.

The crash report led me to believe the error was somewhere other than it actually was.

The error was actually in a SetActorTransform function when calling for the player character to move. The transform was being taken from a and when calling that save game if the string was equal to “” it would fail.

Sorry for the trouble but thank you for reaching out!