Where is it correct to Bind functions to events (in C++)

Previously when working with C++ and binding functions to events, I would’ve done the binding in the classes Ctor.

(for context, I’m referring to binding a classes function to an event of on of its components, such as CapsuleComponents OnComponentBeginOverlap and such)

I’ve learned the hard way that those kind of bindings shouldn’t be done in the Ctor, due to the CDO and undesired behavior due to the order of initializations and such.

I’ve then moved to do so in BeginPlay, just like it’s common in Blueprints.

I’m wondering if there is a better practice, or a more appropriate place to do the binding than BeginPlay? Such as PostInitializeComponents?

I would do it in PostInitializeComponents, because in certain cases, since the order of Begin Play called on actors is not deterministic, you might stumble upon some undesired behavior

For blueprint assigned events using the event binding nodes




these are bound during actor construction, before Begin Play, and I would say is the preferred way to bind events on components

1 Like