Is there a callback that is called when a new component is added to an actor?

I have a class which is an actor and I would like to enforce that only the components that implement a particular interface can be added to this actor. And I would like to do this component validation in C++ code.

Is there a way to achieve this both at Editor time and at Runtime?

1 Like

I don’t know of any callback, but there is the function AActor::AddComponent ( AActor::AddComponent | Unreal Engine Documentation ). I would strongly guess that this is called internally whenever a component should be added to an actor. So for your actor in question you can override this function and if the component implements a certain interface, call the parent method, and if not, simply return NULL (and see what happens, because I havn’t tried it and don’t know what will happen!).

Thanks for the answer Benergy. But I am afraid AddComponent is not a virtual function (I’ve checked this both from source code and documentation). Therefore it cannot be overridden in classes that inherit from AActor.

If it was doable then this would be an elegant answer.

Same problem here. Did you figure this out?

1 Like