Skip to content

Commit

Permalink
using Viewport Stats Subsystem to display permanent error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
MothDoctor committed Aug 23, 2021
1 parent 0d4fcdc commit 00d93ce
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
34 changes: 27 additions & 7 deletions Source/Flow/Private/Nodes/FlowNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand Down Expand Up @@ -356,7 +357,7 @@ void UFlowNode::TriggerOutput(const FName& PinName, const bool bFinish /*= false
{
Finish();
}

#if !UE_BUILD_SHIPPING
if (OutputPins.Contains(PinName))
{
Expand Down Expand Up @@ -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<UViewportStatsSubsystem>())
{
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);
}

Expand Down
7 changes: 7 additions & 0 deletions Source/Flow/Public/FlowTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
2 changes: 1 addition & 1 deletion Source/Flow/Public/Nodes/FlowNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 00d93ce

Please sign in to comment.