diff --git a/Plugins/UEWingman/Source/UEWingman/Private/WingVariables.cpp b/Plugins/UEWingman/Source/UEWingman/Private/WingVariables.cpp index 08927ba9..5b681d0a 100644 --- a/Plugins/UEWingman/Source/UEWingman/Private/WingVariables.cpp +++ b/Plugins/UEWingman/Source/UEWingman/Private/WingVariables.cpp @@ -257,15 +257,15 @@ void WingVariables::Print(WingOut Out) void WingVariables::Load(WingOut Errors) { Empty(); - if (Blueprint != nullptr) return LoadBlueprint(); - if (Graph != nullptr) return LoadGraph(); - if (CustomEvent != nullptr) return LoadCustomEvent(); + if (Blueprint) return LoadBlueprint(); + if (Graph) return LoadGraph(); + if (CustomEvent) return LoadCustomEvent(); ErrorNoBackingStore(Errors); } void WingVariables::LoadBlueprint() { - UObject *CDO = WingUtils::GetGeneratedCDO(Blueprint); + UObject *CDO = WingUtils::GetGeneratedCDO(Blueprint.Get()); for (FBPVariableDescription& Desc : Blueprint->NewVariables) { @@ -281,7 +281,7 @@ void WingVariables::LoadGraph() { TWeakObjectPtr EntryNode; TWeakObjectPtr ResultNode; - FBlueprintEditorUtils::GetEntryAndResultNodes(Graph, EntryNode, ResultNode); + FBlueprintEditorUtils::GetEntryAndResultNodes(Graph.Get(), EntryNode, ResultNode); if (EntryNode.IsValid()) LoadEditablePinBase(EntryNode.Get(), InputVariables); if (ResultNode.IsValid()) LoadEditablePinBase(ResultNode.Get(), OutputVariables); LoadLocalVariables(EntryNode.Get()); @@ -359,7 +359,7 @@ void WingVariables::LoadEditablePinBase(UK2Node_EditablePinBase* Node, WingVaria void WingVariables::LoadCustomEvent() { - LoadEditablePinBase(CustomEvent, InputVariables); + LoadEditablePinBase(CustomEvent.Get(), InputVariables); } bool WingVariables::Check(WingOut Errors) @@ -382,7 +382,7 @@ bool WingVariables::CheckBlueprint(WingOut Errors) bool WingVariables::CheckGraph(WingOut Errors) { - EGraphType T = Graph->GetSchema()->GetGraphType(Graph); + EGraphType T = Graph->GetSchema()->GetGraphType(Graph.Get()); bool AllowLocal = (T == EGraphType::GT_Function); bool AllowInput = (T == EGraphType::GT_Function) || (T == EGraphType::GT_Macro); bool AllowOutput = (T == EGraphType::GT_Function) || (T == EGraphType::GT_Macro); @@ -481,8 +481,8 @@ bool WingVariables::ModifyBlueprintDefaults(WingOut Errors) if (Input.DefaultSpecified) AnySpecified = true; if (!AnySpecified) return true; - FKismetEditorUtilities::CompileBlueprint(Blueprint); - UObject *CDO = WingUtils::GetGeneratedCDO(Blueprint); + FKismetEditorUtilities::CompileBlueprint(Blueprint.Get()); + UObject *CDO = WingUtils::GetGeneratedCDO(Blueprint.Get()); if (!CDO) { Errors.Printf(TEXT("Blueprint didn't compile, cannot store default values")); @@ -535,7 +535,7 @@ bool WingVariables::ModifyCustomEvent(WingOut Errors) { if (!CheckCustomEvent(Errors)) return false; ClearLinks(); - if (!ModifyEditablePinBase(InputVariables, CustomEvent, Errors)) return false; + if (!ModifyEditablePinBase(InputVariables, CustomEvent.Get(), Errors)) return false; CustomEvent->ReconstructNode(); return true; } @@ -567,7 +567,7 @@ bool WingVariables::GetGraphNodes( LocalNode = nullptr; TWeakObjectPtr Inputs, Outputs; - FBlueprintEditorUtils::GetEntryAndResultNodes(Graph, Inputs, Outputs); + FBlueprintEditorUtils::GetEntryAndResultNodes(Graph.Get(), Inputs, Outputs); if (!Inputs.IsValid()) { Errors.Printf(TEXT("ERROR: no function entry node for graph.")); @@ -609,13 +609,13 @@ bool WingVariables::CreateBlueprint(WingOut Errors) // Check for name collisions against existing variables, components, and the like. TSet Names; - FBlueprintEditorUtils::GetClassVariableList(Blueprint, Names); + FBlueprintEditorUtils::GetClassVariableList(Blueprint.Get(), Names); if (!WingUtils::FindNoDuplicateNames(Names, BlueprintVariables.Variables, TEXT("variable or component"), Errors)) return false; // Create the variables. for (const WingVariables::Var& V : BlueprintVariables.Variables) { - if (!FBlueprintEditorUtils::AddMemberVariable(Blueprint, V.Name, V.Type)) + if (!FBlueprintEditorUtils::AddMemberVariable(Blueprint.Get(), V.Name, V.Type)) { Errors.Printf(TEXT("ERROR: Failed to add variable '%s'\n"), *WingUtils::ExternalizeID(V.Name)); @@ -663,10 +663,10 @@ bool WingVariables::CreateGraph(WingOut Errors) AddUserPinInfo(V, EGPD_Input, OutputNode); // Create local variables via the proper API. - UBlueprint* BP = FBlueprintEditorUtils::FindBlueprintForGraph(Graph); + UBlueprint* BP = FBlueprintEditorUtils::FindBlueprintForGraph(Graph.Get()); for (const Var& V : LocalVariables.Variables) { - if (!FBlueprintEditorUtils::AddLocalVariable(BP, Graph, V.Name, V.Type, V.DefaultValue)) + if (!FBlueprintEditorUtils::AddLocalVariable(BP, Graph.Get(), V.Name, V.Type, V.DefaultValue)) { Errors.Printf(TEXT("ERROR: Failed to create local variable '%s'\n"), *WingUtils::ExternalizeID(V.Name)); @@ -692,7 +692,7 @@ bool WingVariables::CreateCustomEvent(WingOut Errors) Names, InputVariables.Variables, TEXT("event parameter"), Errors)) return false; for (const Var& V : InputVariables.Variables) - AddUserPinInfo(V, EGPD_Output, CustomEvent); + AddUserPinInfo(V, EGPD_Output, CustomEvent.Get()); CustomEvent->ReconstructNode(); return true; @@ -729,7 +729,7 @@ bool WingVariables::RemoveBlueprint(WingOut Errors) } // Remove them. - FBlueprintEditorUtils::BulkRemoveMemberVariables(Blueprint, Names); + FBlueprintEditorUtils::BulkRemoveMemberVariables(Blueprint.Get(), Names); return true; } @@ -766,12 +766,12 @@ bool WingVariables::RemoveGraph(WingOut Errors) OutputNode->RemoveUserDefinedPinByName(V.Name); // Remove local variables. - UBlueprint* BP = FBlueprintEditorUtils::FindBlueprintForGraph(Graph); + UBlueprint* BP = FBlueprintEditorUtils::FindBlueprintForGraph(Graph.Get()); for (const Var& V : LocalVariables.Variables) { LocalNode->LocalVariables.RemoveAll( [&](const FBPVariableDescription& Desc) { return Desc.VarName == V.Name; }); - FBlueprintEditorUtils::RemoveVariableNodes(BP, V.Name, true, Graph); + FBlueprintEditorUtils::RemoveVariableNodes(BP, V.Name, true, Graph.Get()); } if (InputNode) InputNode->ReconstructNode(); @@ -798,22 +798,22 @@ bool WingVariables::RemoveCustomEvent(WingOut Errors) bool WingVariables::SetBackingStore(UObject *Obj, WingOut Errors) { - Blueprint = nullptr; - Graph = nullptr; - CustomEvent = nullptr; + Blueprint.Reset(); + Graph.Reset(); + CustomEvent.Reset(); if (UBlueprint *BP = Cast(Obj)) { - Blueprint = BP; + Blueprint.Reset(BP); return true; } if (UEdGraph *G = Cast(Obj)) { - Graph = G; + Graph.Reset(G); return true; } if (UK2Node_CustomEvent *E = Cast(Obj)) { - CustomEvent = E; + CustomEvent.Reset(E); return true; } Errors.Printf(TEXT( diff --git a/Plugins/UEWingman/Source/UEWingman/Public/WingVariables.h b/Plugins/UEWingman/Source/UEWingman/Public/WingVariables.h index d2dc6075..d3def62c 100644 --- a/Plugins/UEWingman/Source/UEWingman/Public/WingVariables.h +++ b/Plugins/UEWingman/Source/UEWingman/Public/WingVariables.h @@ -2,14 +2,14 @@ #include "CoreMinimal.h" #include "EdGraph/EdGraphPin.h" +#include "Engine/Blueprint.h" +#include "K2Node_CustomEvent.h" +#include "UObject/StrongObjectPtr.h" #include "WingBasics.h" struct FBPVariableDescription; struct WingTokenizer; class UObject; -class UBlueprint; -class UEdGraph; -class UK2Node_CustomEvent; class UK2Node_EditablePinBase; class UK2Node_FunctionEntry; struct FUserPinInfo; @@ -92,9 +92,9 @@ public: // The backing store. Only one of these should be set. - UBlueprint *Blueprint = nullptr; - UEdGraph *Graph = nullptr; - UK2Node_CustomEvent *CustomEvent = nullptr; + TStrongObjectPtr Blueprint; + TStrongObjectPtr Graph; + TStrongObjectPtr CustomEvent; // The Workspace. At any given time, these may or may not contain // the same data as the backing store.