How can I add multiple hitboxes actors with default OnHit behavior?
I am trying to add multiple hitboxes (UBoxComponent, USphereComponent, etc.) to different types of actors and specify a default OnHit-Event for those hitboxes and have the whole thing modular so I'm able to add those two hitboxes with their default behavior to any kind of Actor-Blueprint (Character, Pawn, StaticMeshActor, etc.) (and hopefully be able to change the size and location of those hitboxes in each blueprint).
My idea was to create a custom component, containing those two hitboxes and the default events. According to my understanding, such a component could later on be added to any Class-Blueprint to add the hitboxes and their functionality to this Blueprint. I therefore created the following class (HitboxComponent.h):
I was able to compile my code and run it without any problems. But as soon as I try to add this HitboxComponent my Visual Studio breaks (OutputDevice.cpp on line 214) with the following error:
The error appears four times but the editor continues to run and the component is added to the actor. But it seems, that the addition of the component is not working correctly as my Blueprint then looks like this:
After this the blueprint can no longer be compiled (breaks again and prints the same error as before) nor can it be saved anymore with the following error:
I am not sure if it is just not possible to create a component with other components in it or if I am doing something wrong.
I would be very glad if someone could help me solve the problem (or help me get a better idea on how to implement this functionality).
Thanks in advance!
Hey, well let me see if I can help, I'm new to UE4 too, I guess the easyest way to make several hitboxes would be to do it in Blueprint, instead of using UBoxComponent, USphereComponent, you could also just make your own simple mesh - StaticMesh component and make it not visible in game. This could help you making best fit to what you want to do , and you would place it in correct location and set up the HitEvent on the staticMesh component. I would suggest you try to make it work with blueprints first, and then code it if you need to. You could also use AttachTo, to position your components to specific Socket. Maybe try attaching your components to the Root component as well:
(Whenever I was changing the size of default Capsule component, same thing happened to me, for some reason blueprint didn't compile and editor crashed, so thats why I used simple StaticMesh and set a invisible material to it, and it works great and at same time fits exeactly.
Follow this question
Once you sign in you will be able to subscribe for any updates here