Search Unity

[SOLVED] Any way to change namespace of Component / Entity

Discussion in 'Project Tiny' started by reallyhexln, Apr 2, 2019.

  1. reallyhexln

    reallyhexln

    Joined:
    Jun 18, 2018
    Posts:
    69
    Hello for everyone.

    When a component is created it gets the default namespace. Is there any way to change it later?
    Is there any way to set it while creating?
    Is there any way to create a component / entity manually and place it to custom namespace?
     
  2. Pakor

    Pakor

    Joined:
    Feb 2, 2017
    Posts:
    32
    Well I dont know about that, or why you would want it. But you can change the default namespace in the settings. Maybe try something with that?
     
  3. reallyhexln

    reallyhexln

    Joined:
    Jun 18, 2018
    Posts:
    69
    I want to separate common reausable code between multiple games.
    Because components are used in such code, I search for ways to make isolation between it and the game code, perfectly if it will be another namespace.
    I have made some investigation, it seems components and entities is tigtly coupled with editor / runtime, so it's impossible to create them manually.
    I see the only one way to solve dependencies, it's try to use interfaces. So, "common" will be use some interface like IButton that will have the same set of properties like a Button component in the project. Also, it will require the additional file where will be create bindings between interfaces and real components.
    It's about components. When we need to isolate entities, it's enough to create bindings between entities, in the real game, and id in the common code. It's for case when you do not need to guarantee that some entity has expected set of components. Otherwise, it's require some additional code that will be check all components of entity before it's load.
    Taking into account that Tiny will soon switch from ts to c#, I think all of this is over-engineering.
     
  4. raymondyunity

    raymondyunity

    Unity Technologies

    Joined:
    Apr 30, 2018
    Posts:
    98
    Yes, you can create your own modules for your components/data and they will be located in their own namespace.
     
    ER_Dolleman and reallyhexln like this.
  5. reallyhexln

    reallyhexln

    Joined:
    Jun 18, 2018
    Posts:
    69
    Thank you very much. I have seen "Create Module" option but did not paid attention to it.
     
  6. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    2,118
    Could someone clarify this "module" behavior, and how it adds namespaces to files?

    I've created a free tool called SmartNS (https://assetstore.unity.com/packages/tools/utilities/smartns-109633), which automatically inserts namespaces into C# scripts as they're created. It does so dynamically, based on the directory structure into which you place the file. But I wasn't aware of other built-in Unity code that also inserts namespaces into file.

    I don't see anything under "Modules..." for creating custom modules. Could someone clarify how this works so I can confirm if the functionality is compatible with my own namespace-adding functionality? Thanks.