Search Unity

References and namespaces

Discussion in 'Scripting' started by deepdarkblue, Oct 27, 2020.

  1. deepdarkblue

    deepdarkblue

    Joined:
    Sep 17, 2020
    Posts:
    6
    I know both assemblies and namespaces contain classes and methods but what is the difference between references (assemblies) and namespaces?

    References vs Namespaces.PNG View attachment 724726
     
    Last edited: Oct 27, 2020
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,908
    They're pretty much unrelated.

    You can think of an assembly as more or less just a pile of classes that you are bringing into your project.

    Namespaces are just a way to section off class names so that they don't overlap with one another. System.Random and UnityEngine.Random for example are both called "Random", but they can be used together because they have different namespaces.

    By convention, a lot of assemblies put their classes into a few related namespaces, but this is just a convention and not related to the way assemblies work at all. It's possible for two classes from different assemblies to have the same namespace. A namespace doesn't really "contain" anything. It's more just an extended part of the class name.
     
    Bunny83 and deepdarkblue like this.