Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Guidance For Debugging Jobs

Discussion in 'Entity Component System' started by snotbubblelou, Apr 11, 2019.

  1. snotbubblelou

    snotbubblelou

    Joined:
    Jan 17, 2013
    Posts:
    16
    Hello, I am relatively new to working with ECS and I am trying to debug a job, which is not updating values in the components as thought I had specified in the execute function. I am able to validate the system on which the job is schedules is correctly running.

    Where is the guidance (tutorial or otherwise) on ways that I can debug a job? I noted that there is a Job Debugger in the top main menu Jobs->JobsDebugger. Where I can find information on what that is or does? Why is the JobsDebugger listed separately from the EntityDebugger, Frame Debugger, Physics Debugger in the Window->Analysis.
     
  2. NoDumbQuestion

    NoDumbQuestion

    Joined:
    Nov 10, 2017
    Posts:
    186
    Jobs->JobsDebugger is safe handle.
    The way I debug job right now is remove [BurstCompile] and add a bunch of Debug.Log().
    Or convert that IJob -> Entities.ForEach to mainthread code.
    You can also create ChunkQuery, ComponentQuery manually to check length if your entity really exist that frame or at that time.
     
    eterlan and Deleted User like this.
  3. Marius_L

    Marius_L

    Joined:
    Jan 16, 2016
    Posts:
    7
    Another tool is scheduling the job with ScheduleSingle(). This Schedules the job on a single thread.
     
  4. Lieene-Guo

    Lieene-Guo

    Joined:
    Aug 20, 2013
    Posts:
    547
    Try this one, a simple trick.
    Code (CSharp):
    1.     public static class JobLogger
    2.     {
    3.         [BurstDiscard] public static void Log(params object[] parts) => Debug.Log(AppendToString(parts));
    4.         [BurstDiscard] public static void LogWarning(params object[] parts) => Debug.LogWarning(AppendToString(parts));
    5.         [BurstDiscard] public static void LogErrot(params object[] parts) => Debug.LogError(AppendToString(parts));
    6.         public static string AppendToString(params object[] parts)
    7.         {
    8.             System.Text.StringBuilder sb = new System.Text.StringBuilder();
    9.             for (int i = 0, len = parts.Length; i < len; i++) sb.Append(parts[i].ToString());
    10.             return sb.ToString();
    11.         }
    12.     }
     
  5. ProceduralCatMaker

    ProceduralCatMaker

    Joined:
    Mar 9, 2020
    Posts:
    108
    Could you explain its usage a little more in an example? Thanks.
     
  6. Lieene-Guo

    Lieene-Guo

    Joined:
    Aug 20, 2013
    Posts:
    547
    ProceduralCatMaker likes this.
  7. ProceduralCatMaker

    ProceduralCatMaker

    Joined:
    Mar 9, 2020
    Posts:
    108
  8. thebanjomatic

    thebanjomatic

    Joined:
    Nov 13, 2016
    Posts:
    36
    Just throwing it out there as an option that you can debug burst jobs now by attaching a native debugger and stepping through the code.

     
  9. Darkgaze

    Darkgaze

    Joined:
    Apr 3, 2017
    Posts:
    381
    You don't need to remove those. Just disable Burst by going to Jobs menu -> Burst -> Enable Compilation.
     
  10. snotbubblelou

    snotbubblelou

    Joined:
    Jan 17, 2013
    Posts:
    16
    While you are correct, if you are debugging a single file, commenting out [BurstCompile] is more likely faster than drilling through the menu.
     
    Darkgaze likes this.
  11. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    With recent versions, you don't even need to do that.
    Even if there's a BC' error, jobs are still compiled just fine - just not burst compiled.
    Debug.Log works fine, as well as ones with boxed values / strings.
     
    Silrider likes this.
  12. Silrider

    Silrider

    Joined:
    Dec 5, 2019
    Posts:
    5