Skip to content

Commit

Permalink
#57 don't cache node categories, loading blueprint too soon might cau…
Browse files Browse the repository at this point in the history
…se compilation issues

the additional benefit is that Flow Palette would refresh after changing properties of Flow Node class
  • Loading branch information
MothDoctor committed Oct 24, 2021
1 parent 8df0f2b commit 62c02fd
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 43 deletions.
80 changes: 44 additions & 36 deletions Source/FlowEditor/Private/Graph/FlowGraphSchema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@

TArray<UClass*> UFlowGraphSchema::NativeFlowNodes;
TMap<FName, FAssetData> UFlowGraphSchema::BlueprintFlowNodes;

TSet<FString> UFlowGraphSchema::UnsortedCategories;
TArray<TSharedPtr<FString>> UFlowGraphSchema::FlowNodeCategories;

TMap<UClass*, UClass*> UFlowGraphSchema::AssignedGraphNodeClasses;

FFlowGraphSchemaRefresh UFlowGraphSchema::OnNodeListChanged;
Expand Down Expand Up @@ -175,12 +171,42 @@ TSharedPtr<FEdGraphSchemaAction> UFlowGraphSchema::GetCreateCommentAction() cons

TArray<TSharedPtr<FString>> UFlowGraphSchema::GetFlowNodeCategories()
{
if (FlowNodeCategories.Num() == 0)
if (NativeFlowNodes.Num() == 0)
{
GatherFlowNodes();
}

return FlowNodeCategories;
TSet<FString> UnsortedCategories;
for (const UClass* FlowNodeClass : NativeFlowNodes)
{
if (const UFlowNode* DefaultObject = FlowNodeClass->GetDefaultObject<UFlowNode>())
{
UnsortedCategories.Emplace(DefaultObject->GetNodeCategory());
}
}

for (const TPair<FName, FAssetData>& AssetData : BlueprintFlowNodes)
{
if (const UBlueprint* Blueprint = GetPlaceableNodeBlueprint(AssetData.Value))
{
UnsortedCategories.Emplace(Blueprint->BlueprintCategory);
}
}

TArray<FString> SortedCategories = UnsortedCategories.Array();
SortedCategories.Sort();

// create list of categories
TArray<TSharedPtr<FString>> Result;
for (const FString& Category : SortedCategories)
{
if (!Category.IsEmpty())
{
Result.Emplace(MakeShareable(new FString(Category)));
}
}

return Result;
}

UClass* UFlowGraphSchema::GetAssignedGraphNodeClass(const UClass* FlowNodeClass)
Expand Down Expand Up @@ -209,7 +235,7 @@ void UFlowGraphSchema::GetFlowNodeActions(FGraphActionMenuBuilder& ActionMenuBui
}
for (const TPair<FName, FAssetData>& AssetData : BlueprintFlowNodes)
{
if (const UBlueprint* Blueprint = GetNodeBlueprint(AssetData.Value))
if (const UBlueprint* Blueprint = GetPlaceableNodeBlueprint(AssetData.Value))
{
FlowNodes.Emplace(Blueprint->GeneratedClass->GetDefaultObject<UFlowNode>());
}
Expand Down Expand Up @@ -261,9 +287,6 @@ void UFlowGraphSchema::GatherFlowNodes()
if (Class->ClassGeneratedBy == nullptr && IsFlowNodePlaceable(Class))
{
NativeFlowNodes.Emplace(Class);

const UFlowNode* DefaultObject = Class->GetDefaultObject<UFlowNode>();
UnsortedCategories.Emplace(DefaultObject->GetNodeCategory());
}
}

Expand Down Expand Up @@ -297,7 +320,7 @@ void UFlowGraphSchema::GatherFlowNodes()
AddAsset(AssetData, true);
}

RefreshNodeList();
OnNodeListChanged.Broadcast();
}

void UFlowGraphSchema::OnHotReload(EReloadCompleteReason ReloadCompleteReason)
Expand Down Expand Up @@ -338,16 +361,11 @@ void UFlowGraphSchema::AddAsset(const FAssetData& AssetData, const bool bBatch)
// accept only Flow Node blueprints
if (NativeParentClass && NativeParentClass->IsChildOf(UFlowNode::StaticClass()))
{
UBlueprint* Blueprint = GetNodeBlueprint(AssetData);
if (Blueprint && IsFlowNodePlaceable(Blueprint->GeneratedClass))
{
BlueprintFlowNodes.Emplace(AssetData.PackageName, AssetData);
UnsortedCategories.Emplace(Blueprint->BlueprintCategory);
BlueprintFlowNodes.Emplace(AssetData.PackageName, AssetData);

if (!bBatch)
{
RefreshNodeList();
}
if (!bBatch)
{
OnNodeListChanged.Broadcast();
}
}
}
Expand All @@ -361,29 +379,19 @@ void UFlowGraphSchema::OnAssetRemoved(const FAssetData& AssetData)
BlueprintFlowNodes.Remove(AssetData.PackageName);
BlueprintFlowNodes.Shrink();

RefreshNodeList();
OnNodeListChanged.Broadcast();
}
}

void UFlowGraphSchema::RefreshNodeList()
UBlueprint* UFlowGraphSchema::GetPlaceableNodeBlueprint(const FAssetData& AssetData)
{
// sort categories
TArray<FString> SortedCategories = UnsortedCategories.Array();
SortedCategories.Sort();

// create list of categories
FlowNodeCategories.Empty();
for (const FString& Category : SortedCategories)
UBlueprint* Blueprint = Cast<UBlueprint>(AssetData.GetAsset());
if (Blueprint && IsFlowNodePlaceable(Blueprint->GeneratedClass))
{
FlowNodeCategories.Emplace(MakeShareable(new FString(Category)));
return Blueprint;
}

OnNodeListChanged.Broadcast();
}

UBlueprint* UFlowGraphSchema::GetNodeBlueprint(const FAssetData& AssetData)
{
return Cast<UBlueprint>(StaticLoadObject(AssetData.GetClass(), /*Outer =*/nullptr, *AssetData.ObjectPath.ToString(), nullptr, LOAD_NoWarn | LOAD_DisableCompileOnLoad));
return nullptr;
}

#undef LOCTEXT_NAMESPACE
8 changes: 1 addition & 7 deletions Source/FlowEditor/Public/Graph/FlowGraphSchema.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ class FLOWEDITOR_API UFlowGraphSchema : public UEdGraphSchema
private:
static TArray<UClass*> NativeFlowNodes;
static TMap<FName, FAssetData> BlueprintFlowNodes;

static TSet<FString> UnsortedCategories;
static TArray<TSharedPtr<FString>> FlowNodeCategories;

static TMap<UClass*, UClass*> AssignedGraphNodeClasses;

public:
Expand Down Expand Up @@ -50,10 +46,8 @@ class FLOWEDITOR_API UFlowGraphSchema : public UEdGraphSchema
static void OnAssetAdded(const FAssetData& AssetData);
static void AddAsset(const FAssetData& AssetData, const bool bBatch);
static void OnAssetRemoved(const FAssetData& AssetData);

static void RefreshNodeList();

public:
static FFlowGraphSchemaRefresh OnNodeListChanged;
static UBlueprint* GetNodeBlueprint(const FAssetData& AssetData);
static UBlueprint* GetPlaceableNodeBlueprint(const FAssetData& AssetData);
};

0 comments on commit 62c02fd

Please sign in to comment.