Search Unity

Question Force Update UI

Discussion in 'UI Toolkit' started by Nexer8, Sep 20, 2020.

  1. Nexer8

    Nexer8

    Joined:
    Dec 10, 2017
    Posts:
    271
    Working on a tool using the UI Toolkit, but have hit a road block. I can not find a reliable way to force update the UI. I add elements through script, but then I have to switch between Scene View and Game View for the UI to reload(And it does not even work all of the time). Calling OnEnable() for the scene view and for the UI Document did nothing, and I have also tried switching out the visual tree, just to put back the default, but to no luck. Is there a way to force the UI(or some parts of the Visual Tree hierarchy) to update?

    Also found a way to display the UI in scene view(like the UGUI canvas), but that disables the runtime display. Is there any way to both render in the game view and to a render texture?
     
  2. Nexer8

    Nexer8

    Joined:
    Dec 10, 2017
    Posts:
    271
    For future readers, this is what I did to get it working. Apply the code after all of the UI has been generated.
    Code (CSharp):
    1. UnityEditorInternal.InternalEditorUtility.RepaintAllViews();