When a component is added, how would I know?

I’d like to be notified when the user (in editor) adds my UActorComponent subclass.

I’ve noticed adding a component to the actor triggers an OnConstruction call. So I can do my cast here and see if it’s of my component type. However, I’m wondering if there is a better place because OnConstruction seems to be called with every little change. I’m only interested in the add/remove component change.

Hey aoakenfo-

If you want a notification of when your component is created/destroyed, you can add the log message in the Constructor/OnComponentDestroyed functions of the component class. When the component is added, it’s specific constructor is called and the same goes for the OnComponentDestroyed when you call DestoryComponent (from code/blueprints).

Cheers

Thx for the answer. Sorry, I wasn’t clear. I want to be notified inside the Actor, not the component itself. So when the user adds a component of a specific type, I’d like to know. I’ve been using OnConstruction thus far.

After construction, the function UActorComponent::PostInitProperties is called. Which then calls AActor::AddOwnedComponent on it’s owner. UActorComponent::BeginDestroy calls AActor::RemoveOwnedComponent. That is where I would

The functions called on the actor are not virtual, but the ones calling them are.

1 Like

thank you!