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

Question Can't the UQuery method be Used like Transform.Find("A/B/C")?

Discussion in 'UI Toolkit' started by liekong1991, Nov 16, 2021.

  1. liekong1991

    liekong1991

    Joined:
    Nov 15, 2014
    Posts:
    12
    upload_2021-11-16_11-1-31.png

    This is one part of my UI, rootElement is BaseInfoPanel, and I try this, but both of them return null


    Q method can only search for one word?
     
  2. gegagome

    gegagome

    Joined:
    Oct 11, 2012
    Posts:
    389
    Not sure how to help you but your script may solve my problem.
    Could you please share where rootElements came about.
    I am trying to replace the color in the background property of the USS

    Thanks
     
  3. JuliaP_Unity

    JuliaP_Unity

    Unity Technologies

    Joined:
    Mar 26, 2020
    Posts:
    666
    Yes, the Q call will find the element with a specific name, and does not use that pattern. However, if you have an element with a unique name (in your case "Content"), you can find it directly from rootElement because it will recursively find for it - i.e. you don't need to be holding a reference to the immediate parent to get it. So in your example, calling
    rootElement.Q("Content")
    will return you the correct Visual Element.
     
  4. liekong1991

    liekong1991

    Joined:
    Nov 15, 2014
    Posts:
    12
    Just use
    Code (CSharp):
    1. document.rootVisualElement;
    document is the reference of some UIDocument .
     
  5. gegagome

    gegagome

    Joined:
    Oct 11, 2012
    Posts:
    389