How to correctly initialise/use FHitResult*

Hi All

I’ve got FHitResult* and FCollisionQueryParams*, for my line trace function, in the header file and initialized like this;

FHitResult* RV_Hit = new FHitResult(ForceInit);

FCollisionQueryParams* RV_TraceParams = new FCollisionQueryParams(ForceInit);

just before the function is called in the cpp file. The function returns a true on hit, and then on the next line I try and use the getactor() function in the hit result to find out what class it is;

if (RV_Hit->GetActor()->GetClass()->IsChildOf(AInteractor::StaticClass())) {}

This line is crashing the editor. I can’t see anything wrong with it except maybe the FHitResult isnt working?

Any help/advice would be greatly appreciated…

#Try using IsA

And also make sure to check actor is valid before dereferencing it!

AActor* FoundActor = RV_Hit->GetActor();
if(!FoundActor) 
{
  //UE_LOG that actor was not found for some reason
  return;
}

//Is found actor an interactor?
if (FoundActor->IsA(AInteractor::StaticClass())) {}

Let me know if that works!

:slight_smile:

Rama

Great, that worked! The first part of your solution was enough!

I didnt use the IsA bit because they aren’t interactors, they just inherit from that class.

Thanks!!!

Just to clarify your response for other readers, if your classes inherit from AInteractor,

FoundActor->IsA<BaseClass>( )

will return true. If I were to create a class named ABall which inherits from AInteractor, ABall is considered AInteractor and also ABall.