Skip to content

Commit 46d7bad

Browse files
authored
TObjectPtr refactor (#242)
1 parent b040db4 commit 46d7bad

20 files changed

+46
-46
lines changed

Source/Flow/Private/FlowAsset.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ void UFlowAsset::PostLoad()
106106
EDataValidationResult UFlowAsset::ValidateAsset(FFlowMessageLog& MessageLog)
107107
{
108108
// validate nodes
109-
for (const TPair<FGuid, UFlowNode*>& Node : Nodes)
109+
for (const TPair<FGuid, UFlowNode*>& Node : ObjectPtrDecay(Nodes))
110110
{
111111
if (IsValid(Node.Value))
112112
{
@@ -329,7 +329,7 @@ void UFlowAsset::HarvestNodeConnections()
329329
}
330330
}
331331

332-
for (const TPair<FGuid, UFlowNode*>& Pair : Nodes)
332+
for (const TPair<FGuid, UFlowNode*>& Pair : ObjectPtrDecay(Nodes))
333333
{
334334
UFlowNode* FlowNode = Pair.Value;
335335
TMap<FName, FConnectedPin> FoundConnections;
@@ -878,7 +878,7 @@ UFlowNode* UFlowAsset::GetDefaultEntryNode() const
878878
{
879879
UFlowNode* FirstStartNode = nullptr;
880880

881-
for (const TPair<FGuid, UFlowNode*>& Node : Nodes)
881+
for (const TPair<FGuid, UFlowNode*>& Node : ObjectPtrDecay(Nodes))
882882
{
883883
if (UFlowNode_Start* StartNode = Cast<UFlowNode_Start>(Node.Value))
884884
{
@@ -946,7 +946,7 @@ UFlowNode_CustomInput* UFlowAsset::TryFindCustomInputNodeByEventName(const FName
946946

947947
UFlowNode_CustomOutput* UFlowAsset::TryFindCustomOutputNodeByEventName(const FName& EventName) const
948948
{
949-
for (const TPair<FGuid, UFlowNode*>& Node : Nodes)
949+
for (const TPair<FGuid, UFlowNode*>& Node : ObjectPtrDecay(Nodes))
950950
{
951951
if (UFlowNode_CustomOutput* CustomOutput = Cast<UFlowNode_CustomOutput>(Node.Value))
952952
{
@@ -966,7 +966,7 @@ TArray<FName> UFlowAsset::GatherCustomInputNodeEventNames() const
966966
// from the actual flow nodes
967967
TArray<FName> Results;
968968

969-
for (const TPair<FGuid, UFlowNode*>& Node : Nodes)
969+
for (const TPair<FGuid, UFlowNode*>& Node : ObjectPtrDecay(Nodes))
970970
{
971971
if (UFlowNode_CustomInput* CustomInput = Cast<UFlowNode_CustomInput>(Node.Value))
972972
{
@@ -983,7 +983,7 @@ TArray<FName> UFlowAsset::GatherCustomOutputNodeEventNames() const
983983
// from the actual flow nodes
984984
TArray<FName> Results;
985985

986-
for (const TPair<FGuid, UFlowNode*>& Node : Nodes)
986+
for (const TPair<FGuid, UFlowNode*>& Node : ObjectPtrDecay(Nodes))
987987
{
988988
if (UFlowNode_CustomOutput* CustomOutput = Cast<UFlowNode_CustomOutput>(Node.Value))
989989
{
@@ -1099,7 +1099,7 @@ void UFlowAsset::InitializeInstance(const TWeakObjectPtr<UObject> InOwner, UFlow
10991099
Owner = InOwner;
11001100
TemplateAsset = InTemplateAsset;
11011101

1102-
for (TPair<FGuid, UFlowNode*>& Node : Nodes)
1102+
for (TPair<FGuid, TObjectPtr<UFlowNode>>& Node : Nodes)
11031103
{
11041104
UFlowNode* NewNodeInstance = NewObject<UFlowNode>(this, Node.Value->GetClass(), NAME_None, RF_Transient, Node.Value, false, nullptr);
11051105
Node.Value = NewNodeInstance;
@@ -1118,7 +1118,7 @@ void UFlowAsset::InitializeInstance(const TWeakObjectPtr<UObject> InOwner, UFlow
11181118

11191119
void UFlowAsset::DeinitializeInstance()
11201120
{
1121-
for (const TPair<FGuid, UFlowNode*>& Node : Nodes)
1121+
for (const TPair<FGuid, UFlowNode*>& Node : ObjectPtrDecay(Nodes))
11221122
{
11231123
if (IsValid(Node.Value))
11241124
{

Source/Flow/Private/FlowSubsystem.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ void UFlowSubsystem::FinishRootFlow(UObject* Owner, UFlowAsset* TemplateAsset, c
126126
{
127127
UFlowAsset* InstanceToFinish = nullptr;
128128

129-
for (TPair<UFlowAsset*, TWeakObjectPtr<UObject>>& RootInstance : RootInstances)
129+
for (TPair<TObjectPtr<UFlowAsset>, TWeakObjectPtr<UObject>>& RootInstance : RootInstances)
130130
{
131131
if (Owner && Owner == RootInstance.Value.Get() && RootInstance.Key && RootInstance.Key->GetTemplateAsset() == TemplateAsset)
132132
{
@@ -146,7 +146,7 @@ void UFlowSubsystem::FinishAllRootFlows(UObject* Owner, const EFlowFinishPolicy
146146
{
147147
TArray<UFlowAsset*> InstancesToFinish;
148148

149-
for (TPair<UFlowAsset*, TWeakObjectPtr<UObject>>& RootInstance : RootInstances)
149+
for (TPair<TObjectPtr<UFlowAsset>, TWeakObjectPtr<UObject>>& RootInstance : RootInstances)
150150
{
151151
if (Owner && Owner == RootInstance.Value.Get() && RootInstance.Key)
152152
{

Source/Flow/Public/FlowAsset.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ class FLOW_API UFlowAsset : public UObject
159159

160160
private:
161161
UPROPERTY()
162-
TMap<FGuid, UFlowNode*> Nodes;
162+
TMap<FGuid, TObjectPtr<UFlowNode>> Nodes;
163163

164164
#if WITH_EDITORONLY_DATA
165165
protected:
@@ -211,7 +211,7 @@ class FLOW_API UFlowAsset : public UObject
211211
#endif
212212

213213
public:
214-
const TMap<FGuid, UFlowNode*>& GetNodes() const { return Nodes; }
214+
const TMap<FGuid, UFlowNode*>& GetNodes() const { return ObjectPtrDecay(Nodes); }
215215
UFlowNode* GetNode(const FGuid& Guid) const { return Nodes.FindRef(Guid); }
216216

217217
template <class T>
@@ -290,7 +290,7 @@ class FLOW_API UFlowAsset : public UObject
290290
private:
291291
// Original object holds references to instances
292292
UPROPERTY(Transient)
293-
TArray<UFlowAsset*> ActiveInstances;
293+
TArray<TObjectPtr<UFlowAsset>> ActiveInstances;
294294

295295
#if WITH_EDITORONLY_DATA
296296
TWeakObjectPtr<UFlowAsset> InspectedInstance;
@@ -333,7 +333,7 @@ class FLOW_API UFlowAsset : public UObject
333333

334334
protected:
335335
UPROPERTY()
336-
UFlowAsset* TemplateAsset;
336+
TObjectPtr<UFlowAsset> TemplateAsset;
337337

338338
// Object that spawned Root Flow instance, i.e. World Settings or Player Controller
339339
// This pointer is passed to child instances: Flow Asset instances created by the SubGraph nodes
@@ -347,18 +347,18 @@ class FLOW_API UFlowAsset : public UObject
347347

348348
// Optional entry points to the graph, similar to blueprint Custom Events
349349
UPROPERTY()
350-
TSet<UFlowNode_CustomInput*> CustomInputNodes;
350+
TSet<TObjectPtr<UFlowNode_CustomInput>> CustomInputNodes;
351351

352352
UPROPERTY()
353-
TSet<UFlowNode*> PreloadedNodes;
353+
TSet<TObjectPtr<UFlowNode>> PreloadedNodes;
354354

355355
// Nodes that have any work left, not marked as Finished yet
356356
UPROPERTY()
357-
TArray<UFlowNode*> ActiveNodes;
357+
TArray<TObjectPtr<UFlowNode>> ActiveNodes;
358358

359359
// All nodes active in the past, done their work
360360
UPROPERTY()
361-
TArray<UFlowNode*> RecordedNodes;
361+
TArray<TObjectPtr<UFlowNode>> RecordedNodes;
362362

363363
EFlowFinishPolicy FinishPolicy;
364364

Source/Flow/Public/FlowComponent.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ class FLOW_API UFlowComponent : public UActorComponent, public IFlowOwnerInterfa
177177
public:
178178
// Asset that might instantiated as "Root Flow"
179179
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "RootFlow")
180-
UFlowAsset* RootFlow;
180+
TObjectPtr<UFlowAsset> RootFlow;
181181

182182
// If true, component will start Root Flow on Begin Play
183183
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "RootFlow")

Source/Flow/Public/FlowSubsystem.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ class FLOW_API UFlowSubsystem : public UGameInstanceSubsystem
3939
private:
4040
/* All asset templates with active instances */
4141
UPROPERTY()
42-
TArray<UFlowAsset*> InstancedTemplates;
42+
TArray<TObjectPtr<UFlowAsset>> InstancedTemplates;
4343

4444
/* Assets instanced by object from another system, i.e. World Settings or Player Controller */
4545
UPROPERTY()
46-
TMap<UFlowAsset*, TWeakObjectPtr<UObject>> RootInstances;
46+
TMap<TObjectPtr<UFlowAsset>, TWeakObjectPtr<UObject>> RootInstances;
4747

4848
/* Assets instanced by Sub Graph nodes */
4949
UPROPERTY()
50-
TMap<UFlowNode_SubGraph*, UFlowAsset*> InstancedSubFlows;
50+
TMap<TObjectPtr<UFlowNode_SubGraph>, TObjectPtr<UFlowAsset>> InstancedSubFlows;
5151

5252
#if WITH_EDITOR
5353
public:
@@ -60,7 +60,7 @@ class FLOW_API UFlowSubsystem : public UGameInstanceSubsystem
6060

6161
protected:
6262
UPROPERTY()
63-
UFlowSaveGame* LoadedSaveGame;
63+
TObjectPtr<UFlowSaveGame> LoadedSaveGame;
6464

6565
public:
6666
virtual bool ShouldCreateSubsystem(UObject* Outer) const override;
@@ -112,7 +112,7 @@ class FLOW_API UFlowSubsystem : public UGameInstanceSubsystem
112112

113113
/* Returns assets instanced by Sub Graph nodes */
114114
UFUNCTION(BlueprintPure, Category = "FlowSubsystem")
115-
const TMap<UFlowNode_SubGraph*, UFlowAsset*>& GetInstancedSubFlows() const { return InstancedSubFlows; }
115+
const TMap<UFlowNode_SubGraph*, UFlowAsset*>& GetInstancedSubFlows() const { return ObjectPtrDecay(InstancedSubFlows); }
116116

117117
virtual UWorld* GetWorld() const override;
118118

Source/Flow/Public/FlowWorldSettings.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class FLOW_API AFlowWorldSettings : public AWorldSettings
1717

1818
private:
1919
UPROPERTY(BlueprintReadOnly, VisibleAnywhere, Category = "Flow", meta = (AllowPrivateAccess = "true"))
20-
UFlowComponent* FlowComponent;
20+
TObjectPtr<UFlowComponent> FlowComponent;
2121

2222
public:
2323
UFlowComponent* GetFlowComponent() const { return FlowComponent; }

Source/Flow/Public/LevelSequence/FlowLevelSequencePlayer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class FLOW_API UFlowLevelSequencePlayer : public ULevelSequencePlayer
1818
private:
1919
// most likely this is a UFlowNode_PlayLevelSequence or its child
2020
UPROPERTY()
21-
UFlowNode* FlowEventReceiver;
21+
TObjectPtr<UFlowNode> FlowEventReceiver;
2222

2323
public:
2424
// variant of ULevelSequencePlayer::CreateLevelSequencePlayer

Source/Flow/Public/MovieScene/MovieSceneFlowTrack.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,5 @@ class FLOW_API UMovieSceneFlowTrack
6262
private:
6363
/** The track's sections. */
6464
UPROPERTY()
65-
TArray<UMovieSceneSection*> Sections;
65+
TArray<TObjectPtr<UMovieSceneSection>> Sections;
6666
};

Source/Flow/Public/Nodes/FlowNodeBase.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ class FLOW_API UFlowNodeBase
168168
protected:
169169
// Flow Node AddOn attachments
170170
UPROPERTY(BlueprintReadOnly, Instanced, Category = "FlowNode")
171-
TArray<UFlowNodeAddOn*> AddOns;
171+
TArray<TObjectPtr<UFlowNodeAddOn>> AddOns;
172172

173173
protected:
174174
// FlowNodes and AddOns may determine which AddOns are eligible to be their children
@@ -185,7 +185,7 @@ class FLOW_API UFlowNodeBase
185185
virtual const TArray<UFlowNodeAddOn*>& GetFlowNodeAddOnChildren() const { return AddOns; }
186186

187187
#if WITH_EDITOR
188-
virtual TArray<UFlowNodeAddOn*>& GetFlowNodeAddOnChildrenByEditor() { return AddOns; }
188+
virtual TArray<UFlowNodeAddOn*>& GetFlowNodeAddOnChildrenByEditor() { return MutableView(AddOns); }
189189
EFlowAddOnAcceptResult CheckAcceptFlowNodeAddOnChild(const UFlowNodeAddOn* AddOnTemplate, const TArray<UFlowNodeAddOn*>& AdditionalAddOnsToAssumeAreChildren) const;
190190
#endif // WITH_EDITOR
191191

@@ -272,7 +272,7 @@ class FLOW_API UFlowNodeBase
272272
// (some editor symbols exposed to enabled creation of non-editor tooling)
273273

274274
UPROPERTY()
275-
UEdGraphNode* GraphNode;
275+
TObjectPtr<UEdGraphNode> GraphNode;
276276

277277
#if WITH_EDITORONLY_DATA
278278
protected:

Source/Flow/Public/Nodes/FlowPin.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ struct FLOW_API FFlowPin
5555
// (C++ enums must bind by name using SubCategoryEnumName, due to a limitation with UE's UEnum discovery).
5656
// This property is editor-only, but it is automatically copied into PinSubCategoryObject if the PinType matches (for runtime use).
5757
UPROPERTY(EditAnywhere, Category = "FlowPin", meta = (EditCondition = "PinType == EFlowPinType::Enum", EditConditionHides))
58-
UEnum* SubCategoryEnumClass = nullptr;
58+
TObjectPtr<UEnum> SubCategoryEnumClass = nullptr;
5959

6060
// name of enum defined in c++ code, will take priority over asset from EnumType property
6161
// (this is a work-around because EnumClass cannot find C++ Enums,

0 commit comments

Comments
 (0)