UActorComponent::RegisterComponentWithWorld
#include "Components/ActorComponent.h"
Access: public
Description
Registers a component with a world, creating its visual and physical state. Use this to register dynamically created components that were not automatically registered via their owning actor.
Caveats & Gotchas
- • Registering a component that is not attached to a valid actor outer will assert. Always ensure the component has an actor owner before calling RegisterComponentWithWorld.
- • Prefer calling AActor::AddComponent or UActorComponent::RegisterComponent (the shorthand that infers the world from the owning actor) over calling this directly with an explicit world pointer — direct calls risk registering with the wrong world in multi-world or editor scenarios.
Signature
ENGINE_API void RegisterComponentWithWorld(UWorld* InWorld, FRegisterComponentContext* Context = nullptr) Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| InWorld | UWorld* | The world to register the component with. | — |
| Context | FRegisterComponentContext* | Optional context object used during batch registration to defer render state creation. | nullptr |
Return Type
void Example
Dynamically create and register a component at runtime C++
UMyComponent* NewComp = NewObject<UMyComponent>(this, UMyComponent::StaticClass());
NewComp->RegisterComponentWithWorld(GetWorld());
NewComp->AttachToComponent(GetRootComponent(), FAttachmentTransformRules::KeepRelativeTransform); Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?