Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Documentation Errors

Discussion in 'UI Toolkit' started by Claytonious, Jun 17, 2020.

  1. Claytonious

    Claytonious

    Joined:
    Feb 16, 2009
    Posts:
    885
    The manual docs about defining attributes on custom subclasses of VisualElement contains errors that make it hard to get started. They include this example:

    Code (CSharp):
    1. class StatusBar : VisualElement
    2. {
    3.     public new class Factory : UxmlFactory<StatusBar, UxmlTraits> {}
    4.  
    5.     public new class Traits : base.UxmlTraits
    6.     {
    7.         UxmlStringAttributeDescription m_Status = new UxmlStringAttributeDescription { name = "status" };
    8.  
    9.         public override IEnumerable<UxmlChildElementDescription> uxmlChildElementsDescription
    10.         {
    11.             get { yield break; }
    12.         }
    13.  
    14.         public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc)
    15.         {
    16.             base.Init(ve, bag, cc);
    17.             ((StatusBar)ve).status = m_Status.GetValueFromBag(bag, cc);
    18.         }
    19.     }
    20.  
    21.     // ...
    22. }
    Line 3 should refer to Traits instead of UxmlTraits:
    Code (CSharp):
    1. public new class Factory : UxmlFactory<StatusBar, UxmlTraits> {} // <-- WRONG
    2.  
    3. public new class Factory : UxmlFactory<StatusBar, Traits> {} // <-- RIGHT
    ... so that the newly declared inner Traits class is actually used.

    It also uses tries to refer to the base class as "base.UxmlTraits" for some reason, which is a compiler error. Removing ".base" fixes that.
     
  2. stan-osipov

    stan-osipov

    Unity Technologies

    Joined:
    Feb 24, 2020
    Posts:
    31
    Claytonious likes this.