Using reference without object (no new)?

I have question for code from this tutorial:
http://unity3d.com/earn/tutorials/projects/space-shooter/moving-the-player
There is class definition for Boundary.
There is reference created (called boundary).
But there is no “boundary= new Boundary()” line.

Looks like I miss some very important (but basic) concept.

On the other hand, in another tutorial: http://unity3d.com/learn/tutorials/modules/beginner/scripting/classes
‘new’ is called for class Stuff.

You are right, and you would almost always create new classes with new.

But here it works, because Boundary is marked as Serializable and so Unity would create a new instance whenever it (de)serializes it (to be precise, whenever it (de)serializes PlayerController.boundary). So, when you look into the inspector of PlayerController, it will just “magically” be there, because opening inspector performs serialization and creates it.

It is easily possible to break this:

public class BreakPlayerControllerBoundary : MonoBehaviour
{
    void Start()
    {
        PlayerController playerController = gameObject.AddComponent<PlayerController>();
        Debug.Log(playerController.boundary.xMax); // NULL REF EXC
    }
}

Here you would get a NullReferenceException on playerController.boundary, because it was never (de)serialized by Unity and so is still null.

More in-depth info: Serialization in Unity.

Unity sets up (new’s, initializes) all global public vars for you. boundary is a public variable in that script: public Boundary boundary;.

What happens is, when you first add public Boundary boundary;, Unity displays it in the Inspector. That’s a nice feature, so even a non-programmer can easily give it some starting values. It starts with all 0’s, because it has to start somewhere.

It assumes you’re going to type the correct xMin, xMax … into the Inspector. Then, when the game runs, before the script starts, Unity new’s boundary and copies in your numbers. It has to, since how else would the numbers magically get there?

Even if you never change the numbers, since it’s public and you can see those 0’s in the Inspector, the deal is that you get it set up with those 0’s.

The exact way Unity stores the Inspector data is by serializing. If you make a public var in a class that can’t be Serialized (saved,) Unity can’t save the values, so there’s no point showing it in the Inspector.