Gurulis99
(Gurulis99)
1
Hello guys,
i want to access all the attached custom actors of an actor that i have. The attached actors are placed like that:
-Father
---Kid1
-----Kid11
---Kid2
-----Kid11
-----Kid12
---Kid3
How can i access all the Kids of my Father Custom Actor? (Kid1 != Kid11)
Thanks in advance!
Gurulis99
(Gurulis99)
3
Hello, yes this will give only the attached actors. I have customa actors. For example, the Father is , AFather.
MyActor.h
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "MyActor.generated.h"
UCLASS()
class SANDBOX_API AMyActor : public AActor
{
GENERATED_BODY()
UPROPERTY(EditAnywhere)
AActor* Root; // or AFather* Root;
protected:
virtual void BeginPlay() override;
public:
void GetAttachedActorsRecursively(AActor* Parent, TArray<AActor*>& OutActors);
};
MyActor.cpp
#include "MyActor.h"
#include "Child.h"
#include "Father.h"
void AMyActor::BeginPlay()
{
Super::BeginPlay();
TArray<AActor*> Result;
GetAttachedActorsRecursively(Root, Result);
for (AActor* Actor : Result)
{
UE_LOG(LogTemp, Warning, TEXT("%s"), *Actor->GetActorLabel());
// ...
}
}
void AMyActor::GetAttachedActorsRecursively(AActor* Parent, TArray<AActor*>& OutActors)
{
TArray<AActor*> AttachedActors;
Parent->GetAttachedActors(AttachedActors);
for (AActor* Child : AttachedActors)
{
//OutActors.Add(Child); // -> Kid3, Kid2, Kid22, Kid21, Kid1, Kid11
GetAttachedActorsRecursively(Child, OutActors);
OutActors.Add(Child); // -> Kid3, Kid22, Kid21, Kid2, Kid11, Kid1
}
}
Gurulis99
(Gurulis99)
5
That will do the trick!!! Exactly what i wanted. Thank you so much.