Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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):

 class UHitboxComponent : public UActorComponent
     UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Hitbox)
     TSubobjectPtr<class UBoxComponent> FirstHitbox;
     UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Hitbox)
     TSubobjectPtr<class UBoxComponent> SecondHitbox;

And HitboxComponent.cpp:

 UHitboxComponent::UHitboxComponent(const class FPostConstructInitializeProperties& PCIP)
     : Super(PCIP)
     FirstHitbox = PCIP.CreateDefaultSubobject<UBoxComponent>(this, TEXT("First Hitbox"));
     SecondHitbox = PCIP.CreateDefaultSubobject<UBoxComponent>(this, TEXT("Second Hitbox"));

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:

 C:\GitHub\UnrealEngine\Engine\Source\Runtime\Engine\Private\ActorComponent.cpp(120): Ensure condition failed: Owner == NULL || Owner == GetOuter()
 Component Second Hitbox is owned by HitboxCharacter_C_0 by has an Outer of Hitbox1.
 UE4Editor-Win64-Debug.exe has triggered a breakpoint.

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: alt text

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:

 Can't save D:/Unreal Projects/DialogSystem/Content/Blueprints/HitboxCharacter.uasset: Graph is linked to object(s) in external map.
 External Object(s):
 Try to find the chain of references to that object (may take some time)?

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!

Product Version: Not Selected
more ▼

asked Apr 21 '14 at 11:02 PM in C++ Programming

avatar image

8 2 3 5

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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:

 FirstHitbox = PCIP.CreateDefaultSubobject<UBoxComponent>(this, TEXT("First Hitbox"));
 FirstHitbox ->AttachTo(RootComponent);

(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.

more ▼

answered May 17 '14 at 11:31 AM

avatar image

632 27 15 45

avatar image Sneykerrex Jul 06 '14 at 05:42 PM

Thanks for your answer! I didn't even notice I got an answer so excuse my late response :)

I've tried your solution and it seems to work. I did kind of the same thing meanwhile but instead of using a StaticMesh I created an Actor containing the Hitboxes.

I could then add the actor as a ChildActorComponent to my other Actor and got the functionality to work. Sadly both variations aren't exactly modular and easily updateable.

But at least they work, so thanks anyway! :)

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question