I’ve started doing some tests on a project and came up with a problem when trying to bind overlap events to an actor.
I have a static mesh component that generates overlap events
I need to bind a function to the OnActorBeginOverlap (basically the container for the component)
I can obtain the desired outcome by using AddDynamic inside the constructor, however I’ve seen that if I try and use it from inside the BeginPlay this does not work at all and crashes the entire editor as soon as I hit play.
Now, given that there is already a solution to this (just put the code inside the constructor), could someone explain to me why the other method crashes everything?
This is where the line makes the editor crash. If I put it in the constructor everything works fine.
The problem lies in the fact that it seems like if you bind the event in the constructor, this event will stay bound even after removing the line from the constructor and placing it in another function (eg. BeginPlay). The event will try to bind again, but will fail to do so.
I’ve found that if I delete the actual blueprint that inherits from the C++ base class and recreate it (kinda a pain to do since you have to reset so many variables sometimes) it usually fixes the problem. In that case all the events get unbound so that the single event can now be bound during BeginPlay.
Is this considered normal (should I unbind the event in a destructor?) or is it a bug?