am working an Attack function that works by using a ShapeTrace to map out a volume and return the Actors is collides with. My goal is to be able to call the classes derived from the actors that collided with the Trace and trigger some functionality specific to that actor, i.e. if destructible, destroy it or make it invisible.
Currently I am able to map out the shape trace from a button mesh and get a FHitResult that returns the Actors information but I want to get the instances class that is derived from that Actor.
bool isHit = GetWorld()->SweepSingleByChannel(SweepResult, Start, End, FQuat::Identity, ECC_GameTraceChannel1, Shape, CollisionParams);
if (isHit) {
if (SweepResult.bBlockingHit) {
if (GEngine) {
GEngine->AddOnScreenDebugMessage(-1, 2.f, FColor::Red, FString::Printf(TEXT("You are hitting: %s"), *SweepResult.GetActor()->GetName()));
}
ADestructableBox* PointerToObjectThatWillMakeFunctionCall = Cast<ADestructableBox>(SweepResult.GetActor());
if(IsValid(tmp)){
UE_LOG(LogClass, Log, TEXT("Cast Succeeded"));
PointerToObjectThatWillMakeFunctionCall->ResultingEffect();
}
else {
UE_LOG(LogClass, Log, TEXT("Cast Failed"));
}
}
}
I am aware that in blueprints you can cast an Actor to its derived class using the “Cast To ()” node and I am looking for a solution in C++, due to my casting constantly failing.
Also I am aware of the spelling error with the Casting Class