Why your game may be crashing

if you’ve just completed this tutorial on line tracing and find that your program repeatedly crashes when you run it, then the cause may be the lack of this statement:

if(ActorHit) { //… }

This statement is actually extremely important from what I can tell of the program as it checks for invalid pointers (read null pointers). the FHitResult object seems to return a null pointer when the raycast doesn’t find any object to return: a null pointer is a pointer that isn’t assigned to any object and any attempt to access the pointer results in undefined behavior. When you start your game up (assuming you didn’t place the objects right in front of your face) the game will crash as soon as UE_Text accesses the pointer object.

remember that the above if statement is equivalent to:
if(ActorHit does not equal null pointer) { //… }

1 Like

I discovered that myself by trial and error. After using the if statement it quit crashing. Thanks for the explanation.

Thanks!

I’m still doing the challenge, came here desperate for help after some 1 billion crashes. :rage:

To add on to this post, the LineTraceSingleByObjectType() itself returns a bool if a hit happened so it seems like checking the AActor* from hit.GetActor() for not null is not the only way.

Pretty late, but I stumbled upon this also in 4.23. The actor is a nullptr if nothing is hit.

I was like “If it is a null pointer, wouldn’t the engine just inform me (like e.g. Unity does)?”.

It is kind of sad that such a “common” error is not handled properly but makes the whole engine crash.

Privacy & Terms