Question out of Curiosity involving namespaces

Why do we need to state the individual namespaces we want to use in our scripts? Why can’t they all just be built into each script?

What I’m referring to are things like these:

using UnityEngine;
using System.Collections;
etc.
etc.
  1. You don’t want to include all namespaces in your build. Because this would be a huge build. of which you wouldn’t use most. Which is just a waste of disk space.
  2. Define “all”. Your scripts are for instance also in a namespace (If you don’t define it somewhere it will be in the default global namespace). When you use a plugin which is made by someone else, the scripts in this plugin are also in a namespace. So ‘all’ could theoratically be a whole lot more then you might expect :smiley:
  3. Sometimes multiple namespaces contain classes with the same name. A good example of this is the Object class, which exists both in UnityEngine and System (but are 2 different classes). If you would include all namespaces, you would get a lot of conflicts like these.

So for example:

using UnityEngine;
using System;
    
public class Example : MonoBehaviour
{
    public Object something1; // Not allowed, which object do you mean?

    public UnityEngine.Object something2; // allowed

    public System.Object something3; // allowed
}

And I probably forgot some reasons :stuck_out_tongue:

See also : MSDN