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. Dismiss Notice

Resolved Layout update is struggling to process current layout

Discussion in 'UI Toolkit' started by MaNaRz, Jan 3, 2023.

  1. MaNaRz

    MaNaRz

    Joined:
    Aug 24, 2017
    Posts:
    117
    I am recursivly spawning a graph of nodes. Whenever the graph is a bit deeper (like 3 recursions) I get the error:

    "Layout update is struggling to process current layout (consider simplifying to avoid recursive layout): VisualElement unity-panel-container7 (x:0.00, y:0.00, width:871.00, height:505.00) world rect: (x:0.00, y:0.00, width:871.00, height:505.00)
    UnityEngine.GUIUtility: processEvent (int,intptr,bool&) (at /Users/bokken/build/output/unity/unity/Modules/IMGUI/GUIUtility.cs:189)"

    I dont know if it is somehow possible to look at the internal Code to Debug that error.
    Does anyone know what's causing this? How much recursion is too much and why is this an error instead of a warning? I would not care if this takes a few ms since I am doing it very rarely.
     
    dyamanoha_ and tonytopper like this.
  2. antoine-unity

    antoine-unity

    Unity Technologies

    Joined:
    Sep 10, 2015
    Posts:
    733
    Usually this happens when you add new elements or change the position of existing elements during a GeometryChangeEvent callback. The current recursion limit is undocumented and shouldn't be relied upon.

    I think doing this over several frames would be necessary if you need C# logic to nest your graph.
     
  3. MaNaRz

    MaNaRz

    Joined:
    Aug 24, 2017
    Posts:
    117
    Thank you! Your comment helped me solve the issue. I think avoiding GeometryChangeEvent was the key but I can't say for certain. What I do now is to first create all VisualElements recursively. Then later but in the same frame add them all at once to the Visual Hierarchy.

    What's the prefered way of delaying the creation of a VisualElement to the next frame? Which "Update Loop"
    should I hook into?