Characters in my game have multiple hitboxes for hands, feet, and so forth, but every single hitbox has the exact same purpose- notify the parent Actor that something has been hit, and follow whatever logic I’ve prescribed. The way I’m thinking of doing it is creating some class UHitbox.cpp whose only functionality is to create a bunch of USpheres, configure them to the size and dimensions I want, and attach them to the actor’s skeleton in the right place. Then, in AMyCharacter.cpp, I would do something like this:
UHitbox* myHitbox = CreateDefaultSubobject<UHitbox>FName(TEXT("Hitboxes")));
myHitbox ->OnComponentBeginOverlap.AddDynamic( this, &AMyCharacter::SomethingGotHit);
void SomethingGotHit(){
//Find out what was hit, and notify its TakeDamage
}
Two questions arise from this:
- Am I correct in my understanding that if myHitbox has, say, four USpheres, and I add the delegate as I did above, SomethingGotHit will trigger when any of Hitbox’s components that listen for collision touch something?
- Is there a way I can modify OnComponentBeginOverlap to register what triggered the collision? Ideally SomethingGotHit’s logic is going to be to take the reference to what was collided with, determine if it constitutes a valid target, and if it does, message it back in turn.