I don't see the point of these null pointer checks

In our Grabber component we log an error if PhysicsHandle couldn’t be initialized during BeginPlay.

I don’t see the point of adding null pointer checks later on in the code. If you don’t have a PhysicsHandle at this point, you have a problem with your code anyway. The null check just obfuscates the problem, making it both harder to detect and harder to debug.

I can understand that in some very complex projects you might want some non essential parts of your game to fail gracefully instead of crashing, but for our minigame, what’s the value of keeping it running if grabbing the items doesn’t work ?

1 Like

I feel ultimately everyone travels on both sides anyway so at least to me its not a question to care about.

You seem to travel more on let the application hard crash side of things while there are people including games out long ago that travel the catch all errors side and never let it do a hard crash.

So its probably more of just a programmer debate that goes no where really. I guarantee you that there are games from studios that sold millions of copies and you find all kinds of that’s not how you do it faults with their code and yet they sold millions of copies and made lots of money so why even argue it.

There’s one from someone on here who said if statements should use true, not false. Yet there’s a game studio that’s been around for a long time and uses a lot of if false bool statements.

Programmers opinions differ :slight_smile:

It’s better to build these habits now. Not to mention you can warn yourself of an error without the need to crash, if you just include pointer checks and log out when something is wrong (and instructions on how to fix it).

I’d much rather be reminded by my past self in logs with “hey, you didn’t set this component” and just easily press stop and set that component in the editor, rather than crash the whole thing at some line and not remember what I was doing a week ago when writing that code.

It’s a cumulative time saver, and to do it now is to build self-discipline for powerful habits.

2 Likes

Privacy & Terms