AActor::ForEachAttachedActors
#include "GameFramework/Actor.h"
Access: public
Description
Calls a functor for each actor directly attached to any component of this actor. Returning false from the functor stops iteration early.
Caveats & Gotchas
- • Only iterates actors attached directly at one level of the hierarchy — it does not recurse into children of children. Use GetAttachedActors with bRecursivelyIncludeAttachedActors=true if you need the full subtree.
- • Do not attach or detach actors inside the functor body. Modifying the attachment list during iteration will produce undefined behaviour.
Signature
void ForEachAttachedActors(TFunctionRef<bool(class AActor*)> Functor) const Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| Functor | TFunctionRef<bool(class AActor*)> | Callable invoked for each directly attached actor. Return true to continue iteration, false to abort early. | — |
Return Type
void Example
Find the first attached actor of a specific class C++
AWeaponActor* FoundWeapon = nullptr;
GetOwner()->ForEachAttachedActors([&](AActor* Attached) -> bool
{
if (AWeaponActor* Weapon = Cast<AWeaponActor>(Attached))
{
FoundWeapon = Weapon;
return false; // Stop iteration
}
return true; // Continue
}); Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?