Search code examples
unity-game-enginenamespacesencapsulation

Namespacing My Unity Project Scripts


I create tools for the Unity Asset Store and one of my tools is in conflict with other assets people bought from the store which is resulting in unwanted errors. From talking this over with people they said that I should just "namespace TrollBridge{}" EVERY script. Would this be a way of doing it or do I only need to do certain scripts? Even data structure scripts? If it is just certain scripts what exactly am I looking for about these scripts to throw the "namespace TrollBridge {}" on it? I think I understand the whole encapsulation concept with this but maybe I am missing something when it comes to selling tools for other people? Thanks in advance.


Solution

  • Would this be a way of doing it

    Yes.

    or do I only need to do certain scripts?

    Do it for all your scripts.

    Even data structure scripts?

    Yes, even that. All your classes for this should be in a namespace.

    To make this answer short, put all your scripts in a namespace. The reason for this is that you will be distributing this with thousands of people or even hundreds of thousands.

    Let's say that someone is using another plugin called Lighting and that plugin has a class called Lighting. Ask yourself what happens when you release your own plugin with a class called Lighting?

    I have seen this happen before between two plugins which led to many complains. The publisher had to add namespace to all their script which broke many old projects.

    Do it right now so that you won't have this problem in the future. Name your namespace a name you think does not exist in the Asset Store and resonates with the function of your plugin.