OnActorBeginOverlap.AddDynamic() Crashes on BeginPlay
Hi everyone, I've started doing some tests on a project and came up with a problem when trying to bind overlap events to an actor.
The setup: - 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.
Thanks in advance for the insight!
I think I've found what it happens.
So, apparently the reason is that when adding a new event a check is made to make sure that the specific event being added is not already bound to the delegate.
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?
answered Jun 08 '15 at 06:15 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here