How to cast to an actor hit by a trace?

I have recently made a jump from blueprints to C++ and while my first method was successful, I hit a brick wall on something seemingly easy.

I have a simple Actor, that contains a collision volume (box) and an arrow. It also contains a simple method, that is meant to return the location of the arrow once called.

259987-grablocation.png

Now, my actor is shooting a trace out of his face every tick. Once they hit the HandGrabVolume, I would like to know the position of the arrow within that Actor. The problem is, I find myself unable to access that method.
Now, the code itself is already pretty messy - I don’t even check, if the hit Actor is the HandGrabVolume or not - but regardless, I cannot access that method from the Character, because the GetActor() gives me access only to the functions of AActor, not its children.

It’s probably a really basic thing, but I’ve spent this day looking at tutorials and ShooterGame and I haven’t found an example of this type of code done correctly.

Hello,

You need to cast the type of OutHit.GetActor() to your custom type.

AHandGrabVolume* HandGrabActor = Cast<AHandGrabVolume>(OutHit.GetActor());

// Always check casts to make sure they are valid.
// Casts return NULL if the cast failed.
if (HandGrabActor != NULL)
{
    FVector HandGrabLocation = HandGrabActor->GetHandGrabLocation();
}

~ Dennis

Thank you for your help.

I assume I also have to include HandGrabVolume.h in the Character class (and in any other form of Casting)?