WingFetcher stores strong object pointers
This commit is contained in:
@@ -38,22 +38,22 @@ void WingFetcher::SetObj(UObject* InObj)
|
|||||||
{
|
{
|
||||||
if (!bSkipNotify)
|
if (!bSkipNotify)
|
||||||
UWingServer::AddTouchedObject(InObj);
|
UWingServer::AddTouchedObject(InObj);
|
||||||
Obj = InObj;
|
Obj.Reset(InObj);
|
||||||
ResultPin = nullptr;
|
ResultPin = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WingFetcher::SetPin(UEdGraphPin* InPin)
|
void WingFetcher::SetPin(UEdGraphPin* InPin)
|
||||||
{
|
{
|
||||||
ResultPin = InPin;
|
ResultPin = InPin;
|
||||||
Obj = nullptr;
|
Obj.Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
WingFetcher& WingFetcher::SetError()
|
WingFetcher& WingFetcher::SetError()
|
||||||
{
|
{
|
||||||
bError = true;
|
bError = true;
|
||||||
Obj = nullptr;
|
Obj.Reset();
|
||||||
ResultPin = nullptr;
|
ResultPin = nullptr;
|
||||||
OriginalAsset = nullptr;
|
OriginalAsset.Reset();
|
||||||
Editor = nullptr;
|
Editor = nullptr;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -63,7 +63,7 @@ void WingFetcher::PathFailed(const TCHAR* Expected)
|
|||||||
if (ResultPin)
|
if (ResultPin)
|
||||||
Errors.Printf(TEXT("ERROR: Path specifies a pin, but expected %s\n"), Expected);
|
Errors.Printf(TEXT("ERROR: Path specifies a pin, but expected %s\n"), Expected);
|
||||||
else if (Obj)
|
else if (Obj)
|
||||||
Errors.Printf(TEXT("ERROR: Path specifies a %s, but expected %s\n"), *Obj->GetClass()->GetName(), Expected);
|
Errors.Printf(TEXT("ERROR: Path specifies a %s, but expected %s\n"), *Obj.Get()->GetClass()->GetName(), Expected);
|
||||||
else
|
else
|
||||||
Errors.Printf(TEXT("ERROR: Path led to a null pointer\n"));
|
Errors.Printf(TEXT("ERROR: Path led to a null pointer\n"));
|
||||||
UWingServer::SuggestManual(WingManual::Section::Paths);
|
UWingServer::SuggestManual(WingManual::Section::Paths);
|
||||||
@@ -75,7 +75,7 @@ WingFetcher& WingFetcher::TypeMismatch(const TCHAR* Walker, const TCHAR* Expecte
|
|||||||
if (ResultPin)
|
if (ResultPin)
|
||||||
Errors.Printf(TEXT("ERROR: Input to '%s' is a pin, but expected %s\n"), Walker, Expected);
|
Errors.Printf(TEXT("ERROR: Input to '%s' is a pin, but expected %s\n"), Walker, Expected);
|
||||||
else if (Obj)
|
else if (Obj)
|
||||||
Errors.Printf(TEXT("ERROR: Input to '%s' is %s, but expected %s\n"), Walker, *Obj->GetClass()->GetName(), Expected);
|
Errors.Printf(TEXT("ERROR: Input to '%s' is %s, but expected %s\n"), Walker, *Obj.Get()->GetClass()->GetName(), Expected);
|
||||||
else
|
else
|
||||||
Errors.Printf(TEXT("ERROR: Path led to a null pointer\n"));
|
Errors.Printf(TEXT("ERROR: Path led to a null pointer\n"));
|
||||||
UWingServer::SuggestManual(WingManual::Section::Paths);
|
UWingServer::SuggestManual(WingManual::Section::Paths);
|
||||||
@@ -154,16 +154,16 @@ WingFetcher& WingFetcher::Asset(const FString& PackagePath)
|
|||||||
return SetError();
|
return SetError();
|
||||||
}
|
}
|
||||||
|
|
||||||
OriginalAsset = Obj;
|
OriginalAsset.Reset(Obj.Get());
|
||||||
|
|
||||||
// Open the editor for this asset (or bring it to front if already open).
|
// Open the editor for this asset (or bring it to front if already open).
|
||||||
UAssetEditorSubsystem* Sub = GEditor->GetEditorSubsystem<UAssetEditorSubsystem>();
|
UAssetEditorSubsystem* Sub = GEditor->GetEditorSubsystem<UAssetEditorSubsystem>();
|
||||||
if (!Sub || !Sub->OpenEditorForAsset(Obj))
|
if (!Sub || !Sub->OpenEditorForAsset(Obj.Get()))
|
||||||
{
|
{
|
||||||
Errors.Printf(TEXT("ERROR: Could not open editor for '%s'\n"), *PackagePath);
|
Errors.Printf(TEXT("ERROR: Could not open editor for '%s'\n"), *PackagePath);
|
||||||
return SetError();
|
return SetError();
|
||||||
}
|
}
|
||||||
Editor = Sub->FindEditorForAsset(OriginalAsset, false);
|
Editor = Sub->FindEditorForAsset(OriginalAsset.Get(), false);
|
||||||
if (!Editor)
|
if (!Editor)
|
||||||
{
|
{
|
||||||
Errors.Printf(TEXT("ERROR: Could not find editor instance for '%s'\n"), *PackagePath);
|
Errors.Printf(TEXT("ERROR: Could not find editor instance for '%s'\n"), *PackagePath);
|
||||||
@@ -171,7 +171,7 @@ WingFetcher& WingFetcher::Asset(const FString& PackagePath)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If this is a material, use the editor's transient copy.
|
// If this is a material, use the editor's transient copy.
|
||||||
if (UMaterial* Mat = ::Cast<UMaterial>(Obj))
|
if (UMaterial* Mat = ::Cast<UMaterial>(Obj.Get()))
|
||||||
{
|
{
|
||||||
IMaterialEditor *MatEditor = static_cast<IMaterialEditor*>(Editor);
|
IMaterialEditor *MatEditor = static_cast<IMaterialEditor*>(Editor);
|
||||||
SetObj(MatEditor->GetMaterialInterface()->GetBaseMaterial());
|
SetObj(MatEditor->GetMaterialInterface()->GetBaseMaterial());
|
||||||
@@ -182,10 +182,10 @@ WingFetcher& WingFetcher::Asset(const FString& PackagePath)
|
|||||||
bool WingFetcher::CheckAssetIsA(UClass* StaticClass)
|
bool WingFetcher::CheckAssetIsA(UClass* StaticClass)
|
||||||
{
|
{
|
||||||
if (bError) return false;
|
if (bError) return false;
|
||||||
if (!OriginalAsset || !OriginalAsset->IsA(StaticClass))
|
if (!OriginalAsset || !OriginalAsset.Get()->IsA(StaticClass))
|
||||||
{
|
{
|
||||||
Errors.Printf(TEXT("ERROR: Asset is %s, expected %s\n"),
|
Errors.Printf(TEXT("ERROR: Asset is %s, expected %s\n"),
|
||||||
OriginalAsset ? *OriginalAsset->GetClass()->GetName() : TEXT("null"),
|
OriginalAsset ? *OriginalAsset.Get()->GetClass()->GetName() : TEXT("null"),
|
||||||
*StaticClass->GetName());
|
*StaticClass->GetName());
|
||||||
SetError();
|
SetError();
|
||||||
return false;
|
return false;
|
||||||
@@ -198,7 +198,7 @@ WingFetcher& WingFetcher::Graph(const FString& Value)
|
|||||||
if (bError) return *this;
|
if (bError) return *this;
|
||||||
|
|
||||||
// Material with blank graph name
|
// Material with blank graph name
|
||||||
if (UMaterial* Mat = ::Cast<UMaterial>(Obj))
|
if (UMaterial* Mat = ::Cast<UMaterial>(Obj.Get()))
|
||||||
{
|
{
|
||||||
if (!Value.IsEmpty())
|
if (!Value.IsEmpty())
|
||||||
{
|
{
|
||||||
@@ -216,7 +216,7 @@ WingFetcher& WingFetcher::Graph(const FString& Value)
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
UBlueprint* BP = ::Cast<UBlueprint>(Obj);
|
UBlueprint* BP = ::Cast<UBlueprint>(Obj.Get());
|
||||||
if (!BP)
|
if (!BP)
|
||||||
{
|
{
|
||||||
TypeMismatch(TEXT("graph"), TEXT("Blueprint or Material"));
|
TypeMismatch(TEXT("graph"), TEXT("Blueprint or Material"));
|
||||||
@@ -244,7 +244,7 @@ WingFetcher& WingFetcher::Node(const FString& Value)
|
|||||||
if (bError) return *this;
|
if (bError) return *this;
|
||||||
|
|
||||||
// If current object is not a graph, refuse.
|
// If current object is not a graph, refuse.
|
||||||
UEdGraph *Graph = ::Cast<UEdGraph>(Obj);
|
UEdGraph *Graph = ::Cast<UEdGraph>(Obj.Get());
|
||||||
if (Graph == nullptr)
|
if (Graph == nullptr)
|
||||||
{
|
{
|
||||||
TypeMismatch(TEXT("node"), TEXT("Graph"));
|
TypeMismatch(TEXT("node"), TEXT("Graph"));
|
||||||
@@ -271,7 +271,7 @@ WingFetcher& WingFetcher::Pin(const FString& Value)
|
|||||||
{
|
{
|
||||||
if (bError) return *this;
|
if (bError) return *this;
|
||||||
|
|
||||||
UEdGraphNode* N = ::Cast<UEdGraphNode>(Obj);
|
UEdGraphNode* N = ::Cast<UEdGraphNode>(Obj.Get());
|
||||||
if (!N)
|
if (!N)
|
||||||
{
|
{
|
||||||
TypeMismatch(TEXT("pin"), TEXT("node"));
|
TypeMismatch(TEXT("pin"), TEXT("node"));
|
||||||
@@ -295,7 +295,7 @@ WingFetcher& WingFetcher::Component(const FString& Value)
|
|||||||
{
|
{
|
||||||
if (bError) return *this;
|
if (bError) return *this;
|
||||||
|
|
||||||
UBlueprint* BP = ::Cast<UBlueprint>(Obj);
|
UBlueprint* BP = ::Cast<UBlueprint>(Obj.Get());
|
||||||
if (!BP)
|
if (!BP)
|
||||||
{
|
{
|
||||||
TypeMismatch(TEXT("component"), TEXT("Blueprint"));
|
TypeMismatch(TEXT("component"), TEXT("Blueprint"));
|
||||||
@@ -322,7 +322,7 @@ WingFetcher& WingFetcher::Widget(const FString& Value)
|
|||||||
{
|
{
|
||||||
if (bError) return *this;
|
if (bError) return *this;
|
||||||
|
|
||||||
UWidgetBlueprint* WidgetBP = ::Cast<UWidgetBlueprint>(Obj);
|
UWidgetBlueprint* WidgetBP = ::Cast<UWidgetBlueprint>(Obj.Get());
|
||||||
if (!WidgetBP)
|
if (!WidgetBP)
|
||||||
{
|
{
|
||||||
TypeMismatch(TEXT("widget"), TEXT("WidgetBlueprint"));
|
TypeMismatch(TEXT("widget"), TEXT("WidgetBlueprint"));
|
||||||
@@ -349,7 +349,7 @@ WingFetcher& WingFetcher::LevelBlueprint(const FString& Value)
|
|||||||
{
|
{
|
||||||
if (bError) return *this;
|
if (bError) return *this;
|
||||||
|
|
||||||
UWorld* World = ::Cast<UWorld>(Obj);
|
UWorld* World = ::Cast<UWorld>(Obj.Get());
|
||||||
if (!World)
|
if (!World)
|
||||||
{
|
{
|
||||||
TypeMismatch(TEXT("levelblueprint"), TEXT("world"));
|
TypeMismatch(TEXT("levelblueprint"), TEXT("world"));
|
||||||
@@ -389,14 +389,14 @@ WingFetcher& WingFetcher::StructProp(const FString& Value)
|
|||||||
FStructProperty* StructProp = nullptr;
|
FStructProperty* StructProp = nullptr;
|
||||||
|
|
||||||
// The "host" is the object containing this property.
|
// The "host" is the object containing this property.
|
||||||
UObject *HostObject = Obj;
|
UObject *HostObject = Obj.Get();
|
||||||
void *HostBase = Obj;
|
void *HostBase = Obj.Get();
|
||||||
UStruct *HostType = Obj->GetClass();
|
UStruct *HostType = Obj.Get()->GetClass();
|
||||||
bool HostEditable = true;
|
bool HostEditable = true;
|
||||||
|
|
||||||
// If we are *already* inside a UWingStructPointer, update the host
|
// If we are *already* inside a UWingStructPointer, update the host
|
||||||
// fields, to make it possible to navigate even further inside.
|
// fields, to make it possible to navigate even further inside.
|
||||||
if (UWingStructPointer *SPtr = ::Cast<UWingStructPointer>(Obj))
|
if (UWingStructPointer *SPtr = ::Cast<UWingStructPointer>(Obj.Get()))
|
||||||
{
|
{
|
||||||
HostObject = SPtr->Object;
|
HostObject = SPtr->Object;
|
||||||
HostBase = SPtr->StructBase;
|
HostBase = SPtr->StructBase;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "CoreMinimal.h"
|
#include "CoreMinimal.h"
|
||||||
|
#include "UObject/StrongObjectPtr.h"
|
||||||
#include "WingUtils.h"
|
#include "WingUtils.h"
|
||||||
|
|
||||||
class UEdGraphPin;
|
class UEdGraphPin;
|
||||||
@@ -69,7 +70,7 @@ public:
|
|||||||
template<class T> T *Cast()
|
template<class T> T *Cast()
|
||||||
{
|
{
|
||||||
if (bError) return nullptr;
|
if (bError) return nullptr;
|
||||||
T* Result = ::Cast<T>(Obj);
|
T* Result = ::Cast<T>(Obj.Get());
|
||||||
if (Result == nullptr) PathFailed(*T::StaticClass()->GetName());
|
if (Result == nullptr) PathFailed(*T::StaticClass()->GetName());
|
||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
@@ -77,13 +78,13 @@ public:
|
|||||||
// Get the current object as a UObject if it is one,
|
// Get the current object as a UObject if it is one,
|
||||||
// otherwise nullptr. Does not generate errors.
|
// otherwise nullptr. Does not generate errors.
|
||||||
//
|
//
|
||||||
UObject* GetObj() const { return Obj; }
|
UObject* GetObj() const { return Obj.Get(); }
|
||||||
|
|
||||||
// Get the asset from where it all began: the first
|
// Get the asset from where it all began: the first
|
||||||
// step in the walk path. If the asset couldn't be
|
// step in the walk path. If the asset couldn't be
|
||||||
// loaded, returns nullptr. Does not generate errors.
|
// loaded, returns nullptr. Does not generate errors.
|
||||||
//
|
//
|
||||||
UObject* GetAsset() const { return OriginalAsset; }
|
UObject* GetAsset() const { return OriginalAsset.Get(); }
|
||||||
|
|
||||||
// Get the asset from where it all began: the first
|
// Get the asset from where it all began: the first
|
||||||
// step in the walk path, as a specified type. Errors
|
// step in the walk path, as a specified type. Errors
|
||||||
@@ -92,7 +93,7 @@ public:
|
|||||||
template<class T> T* CastAsset()
|
template<class T> T* CastAsset()
|
||||||
{
|
{
|
||||||
if (!CheckAssetIsA(T::StaticClass())) return nullptr;
|
if (!CheckAssetIsA(T::StaticClass())) return nullptr;
|
||||||
return ::Cast<T>(OriginalAsset);
|
return ::Cast<T>(OriginalAsset.Get());
|
||||||
}
|
}
|
||||||
|
|
||||||
// When an asset is loaded, an editor is automatically
|
// When an asset is loaded, an editor is automatically
|
||||||
@@ -127,11 +128,11 @@ public:
|
|||||||
private:
|
private:
|
||||||
|
|
||||||
// The Current Object. Only one of these can be non-null.
|
// The Current Object. Only one of these can be non-null.
|
||||||
UObject* Obj = nullptr;
|
TStrongObjectPtr<UObject> Obj;
|
||||||
UEdGraphPin* ResultPin = nullptr;
|
UEdGraphPin* ResultPin = nullptr;
|
||||||
|
|
||||||
// The Starting Asset and the Editor we Opened.
|
// The Starting Asset and the Editor we Opened.
|
||||||
UObject* OriginalAsset = nullptr;
|
TStrongObjectPtr<UObject> OriginalAsset;
|
||||||
IAssetEditorInstance* Editor = nullptr;
|
IAssetEditorInstance* Editor = nullptr;
|
||||||
|
|
||||||
// True if an error has occurred.
|
// True if an error has occurred.
|
||||||
|
|||||||
Reference in New Issue
Block a user