Skip to content

Commit

Permalink
#63 prevent updating Flow objects while compiling any blueprint
Browse files Browse the repository at this point in the history
  • Loading branch information
MothDoctor committed Oct 24, 2021
1 parent 62c02fd commit abed98a
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 5 deletions.
26 changes: 23 additions & 3 deletions Source/FlowEditor/Private/Graph/FlowGraphSchema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ TArray<UClass*> UFlowGraphSchema::NativeFlowNodes;
TMap<FName, FAssetData> UFlowGraphSchema::BlueprintFlowNodes;
TMap<UClass*, UClass*> UFlowGraphSchema::AssignedGraphNodeClasses;

bool UFlowGraphSchema::bBlueprintCompilationPending;

FFlowGraphSchemaRefresh UFlowGraphSchema::OnNodeListChanged;

UFlowGraphSchema::UFlowGraphSchema(const FObjectInitializer& ObjectInitializer)
Expand All @@ -41,8 +43,8 @@ void UFlowGraphSchema::SubscribeToAssetChanges()

if (GEditor)
{
GEditor->OnBlueprintCompiled().AddStatic(&UFlowGraphSchema::GatherFlowNodes);
GEditor->OnClassPackageLoadedOrUnloaded().AddStatic(&UFlowGraphSchema::GatherFlowNodes);
GEditor->OnBlueprintPreCompile().AddStatic(&UFlowGraphSchema::OnBlueprintPreCompile);
GEditor->OnBlueprintCompiled().AddStatic(&UFlowGraphSchema::OnBlueprintCompiled);
}
}

Expand Down Expand Up @@ -269,11 +271,29 @@ bool UFlowGraphSchema::IsFlowNodePlaceable(const UClass* Class)
return !Class->HasAnyClassFlags(CLASS_Abstract) && !Class->HasAnyClassFlags(CLASS_NotPlaceable) && !Class->HasAnyClassFlags(CLASS_Deprecated);
}

void UFlowGraphSchema::OnBlueprintPreCompile(UBlueprint* Blueprint)
{
if (Blueprint && Blueprint->GeneratedClass && Blueprint->GeneratedClass->IsChildOf(UFlowNode::StaticClass()))
{
bBlueprintCompilationPending = true;
}
}

void UFlowGraphSchema::OnBlueprintCompiled()
{
if (bBlueprintCompilationPending)
{
GatherFlowNodes();
}

bBlueprintCompilationPending = false;
}

void UFlowGraphSchema::GatherFlowNodes()
{
// prevent asset crunching during PIE
if (GEditor && GEditor->PlayWorld)
{
// prevent heavy asset crunching during PIE
return;
}

Expand Down
23 changes: 21 additions & 2 deletions Source/FlowEditor/Private/Graph/Nodes/FlowGraphNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ bool UFlowGraphNode::bFlowAssetsLoaded = false;
UFlowGraphNode::UFlowGraphNode(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
, FlowNode(nullptr)
, bBlueprintCompilationPending(false)
, bNeedsFullReconstruction(false)
{
OrphanedPinSaveMode = ESaveOrphanPinMode::SaveAll;
Expand Down Expand Up @@ -225,12 +226,30 @@ void UFlowGraphNode::SubscribeToExternalChanges()
// blueprint nodes
if (FlowNode->GetClass()->ClassGeneratedBy && GEditor)
{
GEditor->OnBlueprintCompiled().AddUObject(this, &UFlowGraphNode::OnExternalChange);
GEditor->OnClassPackageLoadedOrUnloaded().AddUObject(this, &UFlowGraphNode::OnExternalChange);
GEditor->OnBlueprintPreCompile().AddUObject(this, &UFlowGraphNode::OnBlueprintPreCompile);
GEditor->OnBlueprintCompiled().AddUObject(this, &UFlowGraphNode::OnBlueprintCompiled);
}
}
}

void UFlowGraphNode::OnBlueprintPreCompile(UBlueprint* Blueprint)
{
if (Blueprint && Blueprint == FlowNode->GetClass()->ClassGeneratedBy)
{
bBlueprintCompilationPending = true;
}
}

void UFlowGraphNode::OnBlueprintCompiled()
{
if (bBlueprintCompilationPending)
{
OnExternalChange();
}

bBlueprintCompilationPending = false;
}

void UFlowGraphNode::OnExternalChange()
{
bNeedsFullReconstruction = true;
Expand Down
6 changes: 6 additions & 0 deletions Source/FlowEditor/Public/Graph/FlowGraphSchema.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class FLOWEDITOR_API UFlowGraphSchema : public UEdGraphSchema
static TMap<FName, FAssetData> BlueprintFlowNodes;
static TMap<UClass*, UClass*> AssignedGraphNodeClasses;

static bool bBlueprintCompilationPending;

public:
static void SubscribeToAssetChanges();
static void GetPaletteActions(FGraphActionMenuBuilder& ActionMenuBuilder, const FString& CategoryName);
Expand All @@ -40,6 +42,10 @@ class FLOWEDITOR_API UFlowGraphSchema : public UEdGraphSchema
static void GetCommentAction(FGraphActionMenuBuilder& ActionMenuBuilder, const UEdGraph* CurrentGraph = nullptr);

static bool IsFlowNodePlaceable(const UClass* Class);

static void OnBlueprintPreCompile(UBlueprint* Blueprint);
static void OnBlueprintCompiled();

static void GatherFlowNodes();
static void OnHotReload(EReloadCompleteReason ReloadCompleteReason);

Expand Down
5 changes: 5 additions & 0 deletions Source/FlowEditor/Public/Graph/Nodes/FlowGraphNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class FLOWEDITOR_API UFlowGraphNode : public UEdGraphNode
UPROPERTY(Instanced)
UFlowNode* FlowNode;

bool bBlueprintCompilationPending;
bool bNeedsFullReconstruction;
static bool bFlowAssetsLoaded;

Expand Down Expand Up @@ -85,6 +86,10 @@ class FLOWEDITOR_API UFlowGraphNode : public UEdGraphNode

private:
void SubscribeToExternalChanges();

void OnBlueprintPreCompile(UBlueprint* Blueprint);
void OnBlueprintCompiled();

void OnExternalChange();

//////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit abed98a

Please sign in to comment.