OnComponentBeginOverlap not working
What I'm trying to create is an obstacle that the player will pass through, but get damaged when he does (think of crashing head first into some glass). I have added a new collision profile for it in DefaultEngine.ini like this:
My obstacle class is set up like this:
And the definitions are:
But the event won't fire when the pawn enters the mesh. I tried adding the overlap event in the Blueprint subclass I'm placing in the scene, and it fires there, which means the problem is probably not with the setup of collision profiles and channels, but not in C++. Any ideas why this is happening?
asked Apr 20 '14 at 10:30 AM in C++ Programming
Answering my own question here, but anyway:
The problem was that I had created the blueprint BEFORE adding the code for the overlap part, and for some reason it wasn't working anymore. So I deleted the blueprint and re-created it, and now everything is working fine. Leaves me wondering though, why should this happen at all?
answered Apr 20 '14 at 11:22 AM
As @headstep pointed out on the selected answer's comment, do the event binding on BeginPlay instead of the constructor.
In the constructor only do variable initialisation, and subobject creations. The constructor is executed even in edit mode which is why you see the components you attach to your RootComponent while in the editor. This is similar to how Construction Scripts work on blueprints.
In begin play do things like event bindings, bones attachment, or things that you want done while play time.
answered May 16 '18 at 11:22 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here