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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Calling render early with Debug.Render for debugging purposes?

Discussion in 'Scripting' started by properitconsulting, Nov 4, 2022.

  1. properitconsulting

    properitconsulting

    Joined:
    May 21, 2022
    Posts:
    3
    Hello,

    Is there a way to call the render pipeline directly from code for debugging? It should be something like Debug.Render but that API does not exist.

    I would like to debug my code and see what effect the lines had so far within one frame. Many frameworks have a YieldEvents functions that does exactly that, gives back control to the framework executing all events including graphics.

    The only way to do this in Unity I know of is to rewrite the code to use Coroutines, but that seems to be an overkill to do just for debugging and then I'd have to revert all of my changes after fixing a bug and possibly repeat the whole process in the future again and again.

    Thank you
     
  2. kruskal21

    kruskal21

    Joined:
    May 17, 2022
    Posts:
    68
    Is the Frame Debugger what you are looking for? It allows you to see the entire rendering process, separated into individual drawcalls, within a single frame. If you weren't aware of this tool I highly recommend you to try it out, it's super useful when you are trying to do anything graphics-related.
     
  3. properitconsulting

    properitconsulting

    Joined:
    May 21, 2022
    Posts:
    3
    Hello,

    Unity works in two phases for efficiency reasons:
    1. in MonoBehaviour.Update you "schedule" many graphics calls that you would like to execute in step 2 by creating and manipulating objects
    2. then after the MonoBehaviour.Update method Camera.Render kicks in and it plans, batches and executes the graphics calls so that you can see it on the screen in an efficient way
    The Frame Debugger, as I understand it, allows to you to step through the loop inside Camera.Render, i.e. debug step 2 after the Update. As I am stepping through my code in step 1, before leaving the Update, I would like to ask Unity to run the render calls step 2 "early" so that I can understand what my code is doing, breaking the efficiency but increasing the transparency.

    In a simplified example, if I modify 1000 objects in Update, I would like to render each change separately while in a loop 10 calls deep.
    call1
    call2
    call3​
    ...
    call10
    foreach (o in objects)
    {
    Modify(o);
    Debug.Render(); // this will need to render only the modification of 1 object change not all 1000​
    }​

    Thanks