Unreal Crash on play due to null pointer

Hi, after implementing the if statement to open the door, my editor crashes when clicking play. It appears to be caused by PressurePlate being null on initialization. I was able to fix this by putting the if statement in another if statement like so

if (PressurePlate)
{
if (PressurePlate->IsOverlappingActor(ActorThatOpens))
{
OpenDoor();
}
}

If anyone else has encountered this problem and has other solutions it would be interesting to hear about them.

1 Like

This comes up again later in the section - including other ways to deal with this and other null pointers.

It’s totally normal that you crashed, mind you :slight_smile:

I was experimenting the same issue on linux.
Solution:
if (ActorThatOpens && PressurePlate->IsOverlappingActor(ActorThatOpens))
{
OpenDoor();
}

That wouldn’t protect against anything, since it shouldn’t matter if a nullptr is passed into IsOverlappingActor. If a nullptr is passed in then it should just return false. The crashes would be caused if PressurePlate is nullptr.

Yeah, I had a few editor crashes at this point as well. Easy enough to nut out, but I kind of knew what I was looking for. If someone was coming in raw this could be frustrating. Students will always deviate slightly from the presented content and most of the time reversing an earlier error isn’t too hard to do. As getting something out of alignment here can have a pretty painful effect it might be worth putting null pointer checks into the Into to Pointers section.

Just something to consider.

A.

1 Like

Privacy & Terms