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):
UCLASS(meta=(BlueprintSpawnableComponent))
class UHitboxComponent : public UActorComponent
{
GENERATED_UCLASS_BODY()
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:
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):
BoxComponent_1
BoxComponent_0
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!