RealDocs

UActorComponent::OnComponentCreated

function Engine Since 4.0
#include "Components/ActorComponent.h"
Access: public Specifiers: virtual

Description

Called when a component is created (not loaded from a save). Fires in the editor and at runtime when the component is first instantiated. Use this for one-time setup that should not run on loaded instances.

Caveats & Gotchas

  • Not called when the component is loaded from disk (deserialization path). If your initialization must also run on load, use PostLoad or InitializeComponent instead.
  • In the editor this fires every time the construction script re-runs and creates a new instance of the component — do not assume it fires only once per game session.

Signature

ENGINE_API virtual void OnComponentCreated()

Return Type

void

Example

Performing one-time setup on creation C++
void UMyComponent::OnComponentCreated()
{
    Super::OnComponentCreated();
    // Safe to read owner and set up defaults here
    if (AActor* Owner = GetOwner())
    {
        CachedOwnerName = Owner->GetFName();
    }
}

Version History

Introduced in: 4.0

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.