Namespace - Still a problem?

Unity Doc: 5. Don't use namespaces.

Unity doesn't support placing your scripts inside of a namespace at the moment. This requirement will be removed in a future version.

Can anyone explain me please which cases are critical? I used namespaces without errors. I have the strong feeling that this is obsolet?!

Well, i see the problem with functions like GetComponent(). If you place a class in your own namespace it can't be found only be the classname. You would need to specify the full qualified name `Namespace.Classname` but that's not supported by Unity at the moment. If I place a script (a class derived from MonoBehaviour) in a namespace Unity complains the file name doesn't match the class name if i try to attach it to a gameobject. All the docs are referring to belongs to "scripts". Custom classes (that don't derive from MonoBehaviour) are absolutely no problem since that's just plain .Net / mono.

It's also no problem if you have a base class (that is derived from MonoBehaviour) in a namespace and you inherit a public class from this one.

That script will work as long as the filename matches "Class1". That class can be attached to a GameObject but the Base class can't.

public class Class1 : MyTest.Base
{
}

namespace MyTest
{
    public class Base : MonoBehaviour
    {

    }
}


edit

If you write a seperate C# dll you can use as many namespaces as you want. It seems Unity imports classes from DLLs into the global namespace.

I just tried it :wink:

i saw that the editor scripts from Unity technologies or it's staff use namespaces safely but i think if you create components in namespaces to use in your game (runtime of the player), it's problematic however i never tried to do this exactly for the reason of that text in unity's scripting documentation. i did not see any change to that thing in release notes of unity in any version so we should think that the limitation is still available.

cool thank your for your extensive answers.