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. Dismiss Notice

Custom controls in a custom upm package not showing up in ui builder

Discussion in 'UI Toolkit' started by bamial_grehk, Jun 26, 2020.

  1. bamial_grehk

    bamial_grehk

    Joined:
    Apr 16, 2017
    Posts:
    5
    I verified that moving the custom control class to the unity project script folder causes it to appear in the ui builder. I also checked the "show package files" toggle and other configs that show editor controls etc but to no avail. Is there a way to move custom controls to a package and have them show up in the ui builder right now?
     
    Last edited: Jun 26, 2020
  2. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    1,203
    They should show up. Make sure your custom controls are not in the UnityEngine/UnityEditor.UIElements namespaces. Those are always ignored by the UI Builder. If that still doesn't work, please log a bug via the Bug Reporter.
     
  3. shibi2017

    shibi2017

    Joined:
    Jan 18, 2018
    Posts:
    152
    I saw the Unity Sample UI Builder/toolkit have a custom control window following the UI Document window in the UI builder, but my own project do not have this window. I create a subclass of visualelement, but no custom sontrol shows up. what should i do to fix this problem?

    edit: tossrock is right.
     
    Last edited: Jul 7, 2021
  4. tossrock

    tossrock

    Joined:
    Mar 7, 2018
    Posts:
    12
    I also have this issue. Creating a custom class which extends VisualElement does not yield an entry in the CustomControls section of the Library subwindow of the UI Builder.

    edit: Figured this out - for anyone coming across this post in the future, in order to appear within the UIBuilder, a custom control must:

    1. Inherit from VisualElement, eg
    class NewControl : VisualElement

    2. Have a public UxmlFactory inner class which inherits from UxmlFactory templatized with the custom control name.

    So, a minimal namespaced custom control which will appear in the UIBuilder is as follows:

    Code (CSharp):
    1.  
    2. using UnityEngine.UIElements;
    3.  
    4. namespace com.mygame.ui
    5. {
    6.     class NewControl: VisualElement
    7.     {
    8.         new public class UxmlFactory : UxmlFactory<NewControl>
    9.         {
    10.  
    11.         }
    12.     }
    13. }
    14.  
    15.  
     
    Last edited: Jul 5, 2021
  5. Xepherys

    Xepherys

    Joined:
    Sep 9, 2012
    Posts:
    204
    I am also running into this in 2021.3.8f1. It works when it's part of the root project, but moving it to a Package causes it to not be found and generates the exception: "Element '<element_name>' has no registered factory method."
     
  6. Auroch-ChrisW

    Auroch-ChrisW

    Joined:
    May 4, 2022
    Posts:
    7