UActorComponent
#include "Components/ActorComponent.h"
Access: public
Specifiers: UCLASS
Description
The base class for all actor components. Components are reusable pieces of functionality that can be attached to actors. UActorComponent is the lightest component type — it has no transform. Use USceneComponent for components that need world location/rotation.
Signature
class UActorComponent : public UObject Caveats & Gotchas
- • UActorComponent has no transform. Use USceneComponent if you need 3D positioning.
- • Components are created with `CreateDefaultSubobject<T>()` in the actor's constructor, or dynamically with `NewObject<T>() + RegisterComponent()`.
- • Component tick is separate from actor tick. Enable with `PrimaryComponentTick.bCanEverTick = true`.
- • Calling `DestroyComponent()` marks the component for GC. Detaches it from the owner actor.
Example
Creating a custom component C++
UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
class MYGAME_API UHealthComponent : public UActorComponent
{
GENERATED_BODY()
public:
UHealthComponent();
UPROPERTY(EditAnywhere, BlueprintReadWrite)
float MaxHealth = 100.f;
protected:
float CurrentHealth;
virtual void BeginPlay() override;
};
UHealthComponent::UHealthComponent()
{
PrimaryComponentTick.bCanEverTick = false;
}
void UHealthComponent::BeginPlay()
{
Super::BeginPlay();
CurrentHealth = MaxHealth;
} Functions (3)
Lifecycle 1 ▼
| Access | Type | Name |
|---|---|---|
| protected | function | UActorComponent::BeginPlay |
Components 1 ▼
| Access | Type | Name |
|---|---|---|
| public | function | UActorComponent::DestroyComponent |
Utility 1 ▼
| Access | Type | Name |
|---|---|---|
| public | function | UActorComponent::GetOwner |
Members
Version History
Introduced in: 1.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?