// Copyright 2022 Just2Devs. All Rights Reserved. #include "K2Node_WidgetNodeHelper.h" #include "K2Node_Composite.h" #include "Blueprint/WidgetBlueprintGeneratedClass.h" #include "Kismet2/BlueprintEditorUtils.h" bool FK2Node_WidgetNodeHelper::IsCompatibleWidgetGraph(const UEdGraph* TargetGraph, const bool bTimeBasedNode) { UBlueprint* Blueprint = FBlueprintEditorUtils::FindBlueprintForGraph(TargetGraph); if (Blueprint) { const UEdGraphSchema_K2* K2Schema = Cast(TargetGraph->GetSchema()); check(K2Schema); const bool bSupportsEventGraphs = FBlueprintEditorUtils::DoesSupportEventGraphs(Blueprint); const bool bAllowEvents = (K2Schema->GetGraphType(TargetGraph) == GT_Ubergraph) && bSupportsEventGraphs && (Blueprint->BlueprintType != BPTYPE_MacroLibrary); if (bAllowEvents) { return IsBlueprintWidget(Blueprint); } else { bool bCompositeOfUberGraph = false; // If the composite is a Uber Graph and it doesn't allow events and this is not a time based node return whether we are in a widget or not if(bSupportsEventGraphs && !bAllowEvents && !bTimeBasedNode) { return IsBlueprintWidget(Blueprint); } //If the composite has a Uber Graph in its outer, it is allowed to have timelines if (bSupportsEventGraphs && K2Schema->IsCompositeGraph(TargetGraph)) { while (TargetGraph) { if (const UK2Node_Composite* Composite = Cast(TargetGraph->GetOuter())) { TargetGraph = Cast(Composite->GetOuter()); } else if (K2Schema->GetGraphType(TargetGraph) == GT_Ubergraph) { bCompositeOfUberGraph = true; break; } else { TargetGraph = Cast(TargetGraph->GetOuter()); } } } return bCompositeOfUberGraph ? IsBlueprintWidget(Blueprint) : false; } } return false; } bool FK2Node_WidgetNodeHelper::IsBlueprintWidget(const UBlueprint* Blueprint) { const bool bIsAWidget = Blueprint->GetBlueprintClass()->IsChildOf(UWidgetBlueprintGeneratedClass::StaticClass()) || Blueprint->GetBlueprintClass() == UWidgetBlueprintGeneratedClass::StaticClass(); return bIsAWidget && !FBlueprintEditorUtils::IsActorBased(Blueprint) && FBlueprintEditorUtils::DoesSupportEventGraphs(Blueprint); }