So I’m rather new to unreal and im attempting to create a hitbox system for a fighting game im trying to make, but the hitboxes themselves refuse to enter the function ive linked to OnComponentBeginOverlap… Here’s my function and mesh declarations
//a mesh to show the hitbox
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Hitbox Details")
UStaticMeshComponent * hitbox;
//hitbox collision function
UFUNCTION(BlueprintCallable, Category="Hitboxes")
void OnHit(UPrimitiveComponent* thisHitbox, AActor* otherActor,
UPrimitiveComponent* otherComp, int32 otherBodyIndex,
bool bFromSweep, const FHitResult& SweepResult);
//and Here's my implementation
//set collision types for the mesh and the actual hitbox
hitbox->SetCollisionProfileName(TEXT("OverlapAll"));
//set the hitbox to call OnHit when triggered
hitbox->bGenerateOverlapEvents = true;
hitbox->OnComponentBeginOverlap.AddDynamic(this, &AHitbox::OnHit);
RootComponent = hitbox;
As for the function that im calling, all there is thats of note is a UE_LOG call right at the beginning so i can know whether the function has been entered
UPDATE:
Ok so the hitboxes are actually able to collide with each other, the issue is that a hitbox spawned dynamically through my code isnt colliding
SECOND UPDATE:
so my dynamically spawned hitboxes do in fact have collision, however they don’t actually enter my functions when they collide. Additionally, I tried setting a bGenerateOverlapEvents to false on my character’s capsule collider and that didn’t stop it from entering my function when i walked into the random hitbox i placed in the world. In conclusion, im really confused and if anybody has any internal knowledge that might at least help me figure this out (as in how collision is programmed and works in unreal) that would help. Also, ive already been the the basic this is how collision works in unreal page that has the table with how all their collision types interact with each other
FINAL UPDATE:
Ok so I figured out the answer. Turns out, if you used spawnActor with deferred construction so that your object would run its constructor, then after your actor is fully initialized you need to call FinishSpawning inside the actor itself and pass in its transform
You sure you set up collion chanells and relations? because things can overlap but they can be set to ignore which makes things bypass collision code including event triggers
UStaticMeshComponent * hitbox; … Why? Why not UBoxComponent? If you use static mesh you have to setup Collision on the Mesh you will use with that component.
had to have a visual aspect on the hitboxes and I figured that since static meshes can have collision there wasn’t much point to creating a box component with it
It is showing a cube, and the collision works when i just place one of them in the scene and have it collide with another, the issue is that my dynamically spawned hitboxes arent colliding
Final note since this wasn’t tagged as answered and I just realized that:
If you used spawnActor with deferred construction so that your object would run its constructor, then after your actor is fully initialized you need to call FinishSpawning inside the actor itself and pass in its transform