I have a problem that I cannot solve, so I would like to take this opportunity to ask you a question.
Please understand that we are new to UnrealEngine.
Also, since I am Japanese, I use the translation function, so there is some confusing English.
I am using version 5.0.3.
I implemented the following code in c++, but “Hit” is not displayed in debug.
However, you can get hit detection if you connect it with a blueprint.
This is exactly what the “hit” shows in debug.
Why is it possible in Blueprints but not in C++?
Collision detection can be done with Blueprint, so I think the preset settings are accurate.
You can also check other collision detection like BeginOverlap in c++.
Only OnComponentHit is not available.
You can do it in the constructor if it works for you. But I’ve experienced cases where .AddDynamic would sometimes not work in the constructor, but work on BeginPlay();
If you put it in the constructor and it works, it’s fine.
I’m not sure about this API specifically, but I know that in Unreal, the Constructor is only called once when the engine starts up to create the Class Default Object that future created objects are created from. This should update if the engine Hot Reloads, or if it’s closed down and starts up again. Any time I mess with the constructor, I try and reset the engine, just because I find that functionality gets weird if I don’t and I don’t know what’s updated vs old behaviour.
BeginPlay on the otherhand is when the game starts up, I tend to keep gameplay related things in BeginPlay, as the constructor is called in Editor time, and I just am unsure how well it handles those delegates. I’m sure that it works, I just feel like there is more room there for error on the Engine’s part I guess.