Sorry for using another answer slot. The comment box refuse my (long) answer.
Well, it’s different: I looked at the problem again and I focused on the tile instead of the character. Unless you really want to identify which of its component was hit (other then his feet), you can simply use this scheme to apply damage back to it with minimal fuss.
The static mesh is taken directly from the puzzle template.
I created the collision component in the constructor with dynamic overlapping detection. Then I created a Blueprint and added the mesh as a child in the editor.
ATile::ATile(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{
// Use a box as a simple collision representation
CollisionComp = PCIP.CreateDefaultSubobject<UBoxComponent>(this, TEXT("BoxComp"));
CollisionComp->InitBoxExtent(FVector(250, 250, 20));
CollisionComp->OnComponentBeginOverlap.AddDynamic(this, &ATile::OnTileBeginOverlap);
CollisionComp->OnComponentEndOverlap.AddDynamic(this, &ATile::OnTileEndOverlap);
CollisionComp->SetCollisionProfileName(FName(TEXT("OverlapAllDynamic")));
RootComponent = CollisionComp;
}
Then change the color when you enter the tile’s collision zone. I use a dual color scheme in the material with a parameter change to lerp between both colors.
void ATile::OnTileBeginOverlap(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult)
{
// Use OtherActor to identity character and apply damage.
if (TileMID)
TileMID->SetVectorParameterValue(FName("ColorProgress"), FVector(1.0f));
}
As you leave, bring the param to 0.
void ATile::OnTileEndOverlap(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex )
{
// Use OtherActor to identity character and apply damage.
if (TileMID)
TileMID->SetVectorParameterValue(FName("ColorProgress"), FVector(0.0f));
}
I use OnTile… to avoid name mangling errors due to Blueprints who might have similar names, just like I told you before.