Hard crash in Win64 shipping build when calling PlayerController->PlayerState->UniqueId.ToString()

I’m trying to get the players Steam ID using the following code:

bool UMyFunctionLibrary::GetControllerNetworkID(APlayerController* PlayerController, FString& ID)
{
	if (!PlayerController) return false;
	if (!PlayerController->PlayerState) return false;
	if (!PlayerController->PlayerState->UniqueId->IsValid()) return false;

	ID = PlayerController->PlayerState->UniqueId.ToString();

	return true;
}

This method is exposed as BlueprintCallable and I am calling it ~5 seconds after the game starts (from my GameState class BeginPlay, through a delay node, to this method).

When playing in the editor, playing as a standalone game, and in a DebugGame or Development packaged build this works fine and returns my Steam ID.

In a Win64 Shipping build, however, the game crashes. The UE4 crash reporter tool gives me the following:

Access violation - code c0000005 (first/second chance not available)

Any idea what the problem could be?

I think you want to change line 5 to the following:

if (!PlayerController->PlayerState->UniqueId.IsValid()) return false;

This checks if the TSharedPtr to the FUniqueNetId is valid before calling the FUniqueNetId’s IsValid method

Yeah you’re right, that was causing the crash!