Skip to content

Commit 5f3af70

Browse files
committed
Added a blueprint function to find the top most prefab actor by passing in an input actor
1 parent e7c449a commit 5f3af70

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

Source/PrefabricatorRuntime/Private/Utils/PrefabricatorFunctionLibrary.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,13 @@ void UPrefabricatorBlueprintLibrary::SetPrefabAsset(APrefabActor* PrefabActor, U
7070
}
7171
}
7272

73+
APrefabActor* UPrefabricatorBlueprintLibrary::FindTopMostPrefabActor(AActor* InActor) {
74+
AActor* CurrentActor = InActor;
75+
APrefabActor* TopmostPrefab = nullptr;
76+
while (APrefabActor* PrefabActor = Cast<APrefabActor>(CurrentActor->GetAttachParentActor())) {
77+
TopmostPrefab = PrefabActor;
78+
CurrentActor = PrefabActor;
79+
}
80+
return TopmostPrefab;
81+
}
82+

Source/PrefabricatorRuntime/Public/Utils/PrefabricatorFunctionLibrary.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,8 @@ class PREFABRICATORRUNTIME_API UPrefabricatorBlueprintLibrary : public UBlueprin
2828

2929
UFUNCTION(BlueprintCallable, Category = "Prefabricator")
3030
static void SetPrefabAsset(APrefabActor* PrefabActor, UPrefabricatorAssetInterface* Prefab, bool bReloadPrefab);
31+
32+
UFUNCTION(BlueprintCallable, Category = "Prefabricator")
33+
static APrefabActor* FindTopMostPrefabActor(AActor* InActor);
3134
};
3235

0 commit comments

Comments
 (0)