Position of dynamic binding

Previously the dynamic binding of the event was done in the constructor. Here it is done in the BeginPlay(). What are the benefits of doing this at either location?

The constructor will bind with the object is created, on restarting the editor or reloading the map whereas BeginPlay binds when the play button or game starts.

The main difference is the BeginPlay will enable changes to be made without restarting the editor or loading a different map first. This only applies to items already in the scene such as doors, pressure panels and other such interactive objects. If it’s spawned actors, this would be less of an issue.

Personally I’d use BeginPlay over the constructor simply because in C++ in general, constructor code should only ever be for initialisation of a new class instance. You could argue binding applies to initialisation, but since BeginPlay is available, this is the perfect place to perform these actions.

Really, it is just a matter of preference.

I hope this helps.

Thank you

If you were to do the binding in the constructor but put it there after you created the blueprint then that wouldn’t be applied to existing blueprints so that forces you to either move it to BeginPlay or recreate the blueprint.

This is due to how blueprints are serialised. The same thing happens with changing the default value of a variable in the constructor except you’re able to reset those to the new default by clicking the yellow arrow. You can’t do that with the bindings.

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms