Search Unity

Question What would be the best way to "package" UI items?

Discussion in 'UI Toolkit' started by Kaiymu_, Sep 9, 2020.

  1. Kaiymu_

    Kaiymu_

    Joined:
    Jun 1, 2016
    Posts:
    47
    Hello!

    I would like to create an easy way to "package" some generic UI (UXML / USS / C#) that I would reuse in some other projects

    When trying to do so, the path contained inside the USS / UXML files are breaking because it's changing from project to projects.

    I'm still using Unity 2019.3.15 with UIBuilder (preview-0.0.6).
    And if this is not possible, is that something that would be / is available with UIToolkit on 2020?

    Thank you everyone!
     
  2. JuliaP_Unity

    JuliaP_Unity

    Unity Technologies

    Joined:
    Mar 26, 2020
    Posts:
    698
    Hello! Assuming you're making Editor stuff, have you tried using EditorGUIUtility.Load? Assets in a package are found in the path starting with "Packages/". If you take a look at the PanelSettingsInspector class you can see an example of uss and uxml loading from inside a package path.

    Hope that helps!
     
  3. Kaiymu_

    Kaiymu_

    Joined:
    Jun 1, 2016
    Posts:
    47
    Hello JuliaP!

    To be honest we're using it for runtime :)
    And we don't want to load anything from code, we want it to be smooth (Meaning that our UI artist could just put their assets and be independant).
    Do you see any way of doing so?
     
  4. JuliaP_Unity

    JuliaP_Unity

    Unity Technologies

    Joined:
    Mar 26, 2020
    Posts:
    698
    Can you describe your situation in a bit more detail? The artists are making assets that are shared across different projects, is that it?
     
  5. Kaiymu_

    Kaiymu_

    Joined:
    Jun 1, 2016
    Posts:
    47
    Hello!

    Yes basically the scenario would be as follow :

    We would have our UI team that would create various UI for all of our different teams (For exemple a "Generic Button" that they stylised).
    The idea would be that the other teams would just get the UI package and include these UI inside their project.

    Then, if our artist decide to change how the "Generic Button" is display they would just have to update the package.

    In the end, we want to create a bank of assets available for everyone via the package system!

    Sadly, by having path being written inside the USS "hardcoded" (For exemple : "Assets/MyTexture.png"). We would want to have "Packages/MyTexture.png". The issue is that UIBuilder doesn't see assets inside the Packages folder, so we cannot create our UI like so.
     
  6. JuliaP_Unity

    JuliaP_Unity

    Unity Technologies

    Joined:
    Mar 26, 2020
    Posts:
    698
    It's been a while but I came across your post again and came here to suggest using relative paths (e.g. "../MyTexture.png"; they're relative to the path of the USS file itself). Unfortunately there's no official way to achieve what you're describing :(

    This other post showed up around the same subject though, and some other users were discussing it last week: https://forum.unity.com/threads/how-to-build-a-self-contained-element-cs-uxml-uss.1137925/
     
  7. Kaiymu_

    Kaiymu_

    Joined:
    Jun 1, 2016
    Posts:
    47
    Hello !

    Thank you for your answer !
    So relative path, would basically need me to update the USS file directly right ?
    In that case, even if it's a bit tedious, it would work properly I feel ?
     
  8. JuliaP_Unity

    JuliaP_Unity

    Unity Technologies

    Joined:
    Mar 26, 2020
    Posts:
    698
    Yes, you'd have to update the USS file directly. If it's not working please report back, I just double checked and it works for me here.