Search Unity

Question Path are "hardcoded" and making it impossible to change textures / uss / uxml places

Discussion in 'UI Toolkit' started by Kaiymu_, Jun 3, 2020.

  1. Kaiymu_

    Kaiymu_

    Joined:
    Jun 1, 2016
    Posts:
    47
    Hello,

    I'm trying to change my file to some other folder. By doing so I'm breaking all the game because the reference are not made from the GUID but from a relative path.
    Meaning also that each time I'm renaming a texture a USS or a UXML, everything breaks.

    Is that a bug ? Is their any way to link file without the path?

    For exemple right now I have
    Assets/UI/UXML/MyPage.uxml
    As soon as I change the MyPage.uxml name or path, all the other USS / UXML that references it also break.

    What do I do wrong?

    Thanks.
     
  2. BinaryCats

    BinaryCats

    Joined:
    Feb 8, 2016
    Posts:
    317
    I'm not a fan of this either, but there are several things you can do to make your life easier

    USS/UXML can be serialised by EditorWindow script's default template
    the <Style> property in UXML is also handy as you can apply stylesheets in your UXML (https://docs.unity3d.com/Manual/UIE-WritingUXMLTemplate.html)
     
  3. Kaiymu_

    Kaiymu_

    Joined:
    Jun 1, 2016
    Posts:
    47
    Hello !
    I'm not really sure to follow your idea? How would you do that?

    Currently if I try to edit the UXML / USS with a IDE to change the path from, let's say, Assets/PreviousFolder to Assets/MyNewFolder it's getting messy and crashs.
     
  4. CxydaInno

    CxydaInno

    Joined:
    Sep 5, 2017
    Posts:
    14
    Hey Kaiymu_,
    had a similar issue this morning... one solution is provided in my thread
    https://forum.unity.com/threads/possibilities-to-load-uss-uxml-when-distributed-as-package.905618/

    you could simply call the method i've posted like
    Code (CSharp):
    1. var myUxmlTemplate = LoadFirstAssetByFilter<VisualTreeAsset>("MyPage")
    then at least the path changing should be fixed for you ... renaming the files itself will stay of course but maybe your IDE can help you here.

    edit: Ouhh ...Just realized that you might talk about paths in your uxml (not in the script file) in this case i'd suggest to look into the link BinaryCats provided ... especially the
    src
    and
    path
    attribute section

    Hope this helped
    Best Cxyda
     
    Last edited: Jun 5, 2020
  5. Kaiymu_

    Kaiymu_

    Joined:
    Jun 1, 2016
    Posts:
    47
    Thanks both of your for your answers!
    I'm keeping your idea saved because it's quite interesting and I'll need it for sure in the future!

    I'm working with a lot of UI guys and my focus is to help them be as autonomous as possible, meaning that I want their UI to be finale instead of inserting a lot of stuff by code.

    I'm a bit surprised that UIElements doesn't handle files like "components" where the GUID is stored and not the name / path.
    Maybe it's going to come in a new update!

    Anyway, thanks a lot for your replies :)

    Have a good day.