Search Unity

Assembly Namespaces don't seem to work.

Discussion in 'UI Toolkit' started by Foxaphantsum, Mar 27, 2020.

  1. Foxaphantsum

    Foxaphantsum

    Joined:
    Jul 5, 2013
    Posts:
    139
    In the manual it states its possible to define a define a namespace prefix by doing

    Code (CSharp):
    1. [assembly: UxmlNamespacePrefix("My.First.Namespace", "first")]
    The issue I'm facing is that this doesn't appear to work correctly. I've tried all kinds of combinations to get the newly defined namespace to work and I'm clueless as to how to get this working properly.

    I constantly get an error about a factory for a custom element not existing unless I put the .cs script into the same namespace as the uxml for my custom editor UI.


     
  2. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    1,231
    This namespace prefix in your assembly is not necessary. It is only used when creating the schema for UXML so it knows about your namespaces and how it should auto-complete when typing UXML.

    If you post your UXML and how you try to instantiate it I can help identify why it's not working. First thing to always try is the full type name, including namespace. So for something like this:

    Code (CSharp):
    1. namespace MySpace {
    2.      class MyElement : VisualElement {
    3.            public new class UxmlFactory : UxmlFactory<MyElement, UxmlTraits> { }
    4.      }
    5. }
    You would add it to UXML like so:
    Code (CSharp):
    1. <MySpace.MyElement />
     
    Mrbeardy likes this.