Search Unity

Official Feeback wanted : UI assets Live Reload

Discussion in 'UI Toolkit' started by antoine-unity, Sep 2, 2020.

  1. antoine-unity

    antoine-unity

    Unity Technologies

    Joined:
    Sep 10, 2015
    Posts:
    780
    Starting with with com.unity.ui at version 1.0.0-preview.8 and UI Builder at version 1.0.0-preview.5, UXML and USS files, both for Editor Windows and Runtime (UIDocument), can be updated in real time as changes are made in the UI Builder.

    For Editor Windows, it's off by default and can be turned on through the window's menu (the 3 vertical dots). Once it's turned on/off, it applies to all windows of the same type.

    For Runtime, it's on by default and controlled by the same setting in the Game View. It will then apply to all Game views.





    If files are modified in disk, and not in memory (i.e. UI Builder changes are made in memory), they get reloaded as well, as was already the case before this release (although it's more optimized now for Unity 2020.2).

    Editor Windows
    No change is expected from users in order for their Editor Window to be compatible with Live Reload, other than users should be aware that the whole UI is recreated, which means that if they need to save some state/value on it, they have to do it in a way that guarantees the recreation of the window will bring it back to the desired state.

    Runtime
    If users add companion MonoBehaviour components to the same Game Object containing the UIDocument component, when the UI is reloaded it will cause these companions to be disabled (prior to the reload) and then re-enabled (after the reload). Therefore, users can place code that interacts with the UI on the OnEnable and OnDisable methods of those companions for initialization and teardown, respectively.

    Unity version differences (2020.1 / 2020.2)

    Users will be able to use Live Reload for Editor Windows in Unity 2020.2, but not on 2020.1 due to limitations of our package on this version.

    ---

    We'd like to hear from you! Is this feature useful for you? Are you encountering challenges dealing with Live Reload within your scripts?
     
  2. nmad

    nmad

    Joined:
    Jul 28, 2013
    Posts:
    8
    For me, it could be very useful, so we can preview changes also in affected elements without having to deselect/select them again ...I also made something similar but by creating a new button which basically re-triggers the method that adds the uxml file and adds all event hooks... but if that feature can be added by default it would be awesome :)
     
  3. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,188
    I found an inconvenience: I'm used to EditorWindow serializing valued through recompile or playmode just by having the fields within the window be serializable. However, now, with live reload, the entire serialized state gets destroyed and recreated.

    Is this required to make this feature work? If not, I'd consider it a bug and would prefer editor windows to reuse the existing serialized data like they normally do. For example, previously I could do this:

    Code (CSharp):
    1. public class MyWindow : EditorWindow
    2. {
    3.     [SerializeField]
    4.     private ScriptableObject someObject;
    5.  
    6.     private void Awake()
    7.     {
    8.         if (someObject == null)
    9.         {
    10.             // Create some ScriptableObject instance and make it survive playmode.
    11.             someObject = ScriptableObject.CreateInstance<ScriptableObject>();
    12.             someObject.hideFlags = HideFlags.DontSave;
    13.         }
    14.     }
    15.  
    16.     private void OnDestroy()
    17.     {
    18.         if (someObject != null)
    19.             DestroyImmediate(someObject);
    20.     }
    21. }
    But when I make a change to the editor window's USS file and it is reloaded, "someObject" is destroyed. I'm not really sure if this is intended and I'd like to have serialized data that is kept alive during recompile and playmode but doesn't need to be saved to disk otherwise.

    @antoine-unity Please let me know if this description makes sense or if I should prepare a repro project.