AActor::OwnsComponent
#include "GameFramework/Actor.h"
Access: public
Specifiers: const
Description
Returns true if the component is present in this actor's OwnedComponents set. Intended as a validation helper in assert/check contexts.
Caveats & Gotchas
- • This function is only compiled when `DO_CHECK` or `USING_CODE_ANALYSIS` is defined. In Shipping builds the function does not exist — code that calls it must be wrapped in `#if DO_CHECK` or it will fail to compile in Shipping.
- • Returns false for components that are owned by a child actor inside a ChildActorComponent, even though those components are logically 'part of' this actor hierarchy.
- • Use only for debug assertions, not for runtime logic. Prefer checking `Component->GetOwner() == this` for runtime ownership tests.
Signature
bool OwnsComponent(UActorComponent* Component) const Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| Component | UActorComponent* | The component to test for ownership. | — |
Return Type
bool Example
Debug assertion guarding component manipulation C++
#if DO_CHECK
check(OwnsComponent(MyComp));
#endif
MyComp->SetActive(true); Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?