From 00d93cee8305ee5d4bfc094926a5f446423ab9cf Mon Sep 17 00:00:00 2001 From: Moth Doctor Date: Mon, 23 Aug 2021 23:50:20 +0200 Subject: [PATCH] using Viewport Stats Subsystem to display permanent error messages --- Source/Flow/Private/Nodes/FlowNode.cpp | 34 ++++++++++++++++++++------ Source/Flow/Public/FlowTypes.h | 7 ++++++ Source/Flow/Public/Nodes/FlowNode.h | 2 +- 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/Source/Flow/Private/Nodes/FlowNode.cpp b/Source/Flow/Private/Nodes/FlowNode.cpp index 48353f6b..eb5ee2f5 100644 --- a/Source/Flow/Private/Nodes/FlowNode.cpp +++ b/Source/Flow/Private/Nodes/FlowNode.cpp @@ -6,6 +6,7 @@ #include "FlowTypes.h" #include "Engine/Engine.h" +#include "Engine/ViewportStatsSubsystem.h" #include "Engine/World.h" #include "Misc/App.h" #include "Misc/Paths.h" @@ -15,10 +16,10 @@ FFlowPin UFlowNode::DefaultInputPin(TEXT("In")); FFlowPin UFlowNode::DefaultOutputPin(TEXT("Out")); -FString UFlowNode::MissingIdentityTag = TEXT("Missing Identity Tag!"); -FString UFlowNode::MissingNotifyTag = TEXT("Missing Notify Tag!"); -FString UFlowNode::MissingClass = TEXT("Missing class!"); -FString UFlowNode::NoActorsFound = TEXT("No actors found!"); +FString UFlowNode::MissingIdentityTag = TEXT("Missing Identity Tag"); +FString UFlowNode::MissingNotifyTag = TEXT("Missing Notify Tag"); +FString UFlowNode::MissingClass = TEXT("Missing class"); +FString UFlowNode::NoActorsFound = TEXT("No actors found"); UFlowNode::UFlowNode(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer) @@ -356,7 +357,7 @@ void UFlowNode::TriggerOutput(const FName& PinName, const bool bFinish /*= false { Finish(); } - + #if !UE_BUILD_SHIPPING if (OutputPins.Contains(PinName)) { @@ -551,12 +552,31 @@ FString UFlowNode::GetProgressAsString(float Value) return TempString; } -void UFlowNode::LogError(FString Message) const +void UFlowNode::LogError(FString Message, const EFlowOnScreenMessageType OnScreenMessageType) const { const FString TemplatePath = GetFlowAsset()->TemplateAsset->GetPathName(); Message += TEXT(" in node ") + GetName() + TEXT(", asset ") + FPaths::GetPath(TemplatePath) + TEXT("/") + FPaths::GetBaseFilename(TemplatePath); - GEngine->AddOnScreenDebugMessage(-1, 2.0f, FColor::Red, Message); + if (OnScreenMessageType == EFlowOnScreenMessageType::Permanent) + { + if (GetWorld()) + { + if (UViewportStatsSubsystem* StatsSubsystem = GetWorld()->GetSubsystem()) + { + StatsSubsystem->AddDisplayDelegate([this, Message](FText& OutText, FLinearColor& OutColor) + { + OutText = FText::FromString(Message); + OutColor = FLinearColor::Red; + return !IsPendingKill() && ActivationState != EFlowNodeState::NeverActivated; + }); + } + } + } + else + { + GEngine->AddOnScreenDebugMessage(-1, 2.0f, FColor::Red, Message); + } + UE_LOG(LogFlow, Error, TEXT("%s"), *Message); } diff --git a/Source/Flow/Public/FlowTypes.h b/Source/Flow/Public/FlowTypes.h index b1a6b390..38344448 100644 --- a/Source/Flow/Public/FlowTypes.h +++ b/Source/Flow/Public/FlowTypes.h @@ -41,3 +41,10 @@ enum class EFlowNetMode : uint8 ServerOnly UMETA(ToolTip = "Executed on the server"), SinglePlayerOnly UMETA(ToolTip = "Executed only in the single player, not available in multiplayer.") }; + +UENUM(BlueprintType) +enum class EFlowOnScreenMessageType : uint8 +{ + Temporary, + Permanent +}; diff --git a/Source/Flow/Public/Nodes/FlowNode.h b/Source/Flow/Public/Nodes/FlowNode.h index 66103f64..300c4874 100644 --- a/Source/Flow/Public/Nodes/FlowNode.h +++ b/Source/Flow/Public/Nodes/FlowNode.h @@ -331,7 +331,7 @@ class FLOW_API UFlowNode : public UObject, public IVisualLoggerDebugSnapshotInte static FString GetProgressAsString(float Value); UFUNCTION(BlueprintCallable, Category = "FlowNode") - void LogError(FString Message) const; + void LogError(FString Message, const EFlowOnScreenMessageType OnScreenMessageType = EFlowOnScreenMessageType::Permanent) const; UFUNCTION(BlueprintCallable, Category = "FlowNode") void SaveInstance(FFlowNodeSaveData& NodeRecord);