So I’m stuck with this issue of not being able to find a BP actor in my C++ code.
I used LineTraceSingleByObjectType then I put the result in a FHitResult called hit.
Basically I want to compare my blueprint actor with what is in hit.GetActor().
Any advices will be appreciated.
PS : My other code works fine if I remove the if statement.
The code below crashes when it arrives at the if statement.
Thank you
AActor* actorHit = hit.GetActor();
If (actorHit->GetName() == "myActor_BP") //
{
//Do something useful here
}
Your actorHit is not guaranteed to have a valid value, meaning, it might not point to an actor. After all, your LineTrace might not find a compatible target to hit.
Since you are trying to call a function on an object that in some cases might be nullptr, the engine crashes.
Put an “if(!actorHit) return;” or some kind of similar structure before your if, checking if your actorHit field is valid first.