Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void UKismetSystemLibrary::PrintString(UObject* WorldContextObject, const FString& InString, bool bPrintToScreen, bool bPrintToLog, FLinearColor TextColor)
- {
- #if !(UE_BUILD_SHIPPING || UE_BUILD_TEST) // Do not Print in Shipping or Test
- WorldContextObject = GEngine->GetWorldFromContextObject(WorldContextObject, false);
- FString Prefix;
- if (WorldContextObject)
- {
- UWorld *World = WorldContextObject->GetWorld();
- if (World->WorldType == EWorldType::PIE)
- {
- switch(World->GetNetMode())
- {
- case NM_Client:
- Prefix = FString::Printf(TEXT("Client %d: "), GPlayInEditorID - 1);
- break;
- case NM_DedicatedServer:
- case NM_ListenServer:
- Prefix = FString::Printf(TEXT("Server: "));
- break;
- }
- }
- }
- const FString FinalString = Prefix + InString;
- if (bPrintToLog)
- {
- UE_LOG(LogBlueprintUserMessages, Log, TEXT("%s"), *FinalString);
- APlayerController* PC = (WorldContextObject ? UGameplayStatics::GetPlayerController(WorldContextObject, 0) : NULL);
- ULocalPlayer* LocalPlayer = (PC ? Cast<ULocalPlayer>(PC->Player) : NULL);
- if (LocalPlayer && LocalPlayer->ViewportClient && LocalPlayer->ViewportClient->ViewportConsole)
- {
- LocalPlayer->ViewportClient->ViewportConsole->OutputText(FinalString);
- }
- }
- else
- {
- UE_LOG(LogBlueprintUserMessages, Verbose, TEXT("%s"), *FinalString);
- }
- // Also output to the screen, if possible
- if (bPrintToScreen)
- {
- if (GAreScreenMessagesEnabled)
- {
- float Duration = 2.0f;
- if ( GConfig )
- {
- GConfig->GetFloat( TEXT("Kismet"), TEXT("PrintStringDuration"), Duration, GEngineIni );
- }
- GEngine->AddOnScreenDebugMessage((uint64)-1, Duration, TextColor.ToFColor(true), FinalString);
- }
- else
- {
- UE_LOG(LogBlueprint, VeryVerbose, TEXT("Screen messages disabled (!GAreScreenMessagesEnabled). Cannot print to screen."));
- }
- }
- #endif
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement