I’m learning C# and I usually understand everything but I’m having trouble knowing what I will actually ever use null for.
you will use it… a lot…
your question is hard to answer, you will reply it yourself when you start practicing and following tutorials
is like asking “what will you use the number 0 for?”
You will mostly use it to compare to variables to make sure you actually have a reference to something that exists so you don’t cause a NullReferenceException.
Reference variables are initially set to null. You’ll know that your variables are not set up properly if they are null.
Sometimes functions will return null if they don’t find anything (Eg: GetComponent<>()), so you check against null to see if that function failed.
The thing is, if you try to send a command to an object that doesn’t exist, the computer will have no idea what to do and give up. Every variable can’t automatically be filled, so they start off set to null until the variable is set properly. (Eg: Try accessing rigidbody, collider, particleSystem, etc. on GameObjects that don’t have those things. They will be set to null.)
There are some other things that null can be used for, but avoiding NullReferenceException is by far the most common thing.
I use them all the time. Like when you set up something that returns a vector3 instead of void for example, if your logic fails it returns null.
In a game i’m working on at work we’re looking for a waypoint, if waypoint is null then something happens.
Well this for example:
public Transform target = null;
You will use it for initialisation, null reference checking and null forcing on variables.