Search Unity

Console Logging (Debug.Log) equivalent for DOTS? (inside job's execute)

Discussion in 'Entity Component System' started by Mr-Mechanical, Jan 12, 2020.

  1. Mr-Mechanical

    Mr-Mechanical

    Joined:
    May 31, 2015
    Posts:
    507
    Hello,

    I am interested in printing certain values to assist in the debugging process. Is there any existing equivalent to Debug.Log with DOTS? I understand there is a limitation with printing to console being traditionally done from the main thread.

    Thanks.
     
  2. RoughSpaghetti3211

    RoughSpaghetti3211

    Joined:
    Aug 11, 2015
    Posts:
    1,705
    I do this , probably a better way but for quick debug log it works


    Code (CSharp):
    1.         [BurstCompile]
    2.         private struct SetData : IJobForEachWithEntity<EntityDataComponent>
    3.         {
    4.             public void Execute(Entity entity, int index, ref EntityDataComponent c)
    5.             {
    6.                 // WARNING : This does not print to console for some reason but the
    7.                 // job is working.
    8.                 DebugInfo();
    9.  
    10.                 c.EntityData = index;
    11.             }
    12.  
    13.             [BurstDiscard]
    14.             private void DebugInfo()
    15.             {
    16.                 Debug.Log("<b> <size=13> <color=#9DF155>Info : 3 SetDataSystem : Setting Data .</color> </size> </b>");
    17.             }
    18.         }
    for the most part
     
    Mr-Mechanical likes this.
  3. Mr-Mechanical

    Mr-Mechanical

    Joined:
    May 31, 2015
    Posts:
    507
    Thank you for sharing!

    Optimally I would like to print some value computed inside execute function to make sure all is well with my code. Can your print whatever with your DebugInfo example? Finding some way to print/log inside execute could be extremely useful for debugging quickly.
     
  4. RoughSpaghetti3211

    RoughSpaghetti3211

    Joined:
    Aug 11, 2015
    Posts:
    1,705
    Ah yea I’m not sure. Honestly after getting rider IDE ive not really haven’t log anything for waht I’m doing.
     
  5. Mr-Mechanical

    Mr-Mechanical

    Joined:
    May 31, 2015
    Posts:
    507
    I would really like to test my code by printing inside a Job's execute's function to see what is going on. Any way this is possible? I am willing to sacrifice performance temporarily for testing... Perhaps there's a magic way to make everything run on the main thread to use debug.log (disable multithreading for debugging or something)?
     
  6. Sarkahn

    Sarkahn

    Joined:
    Jan 9, 2013
    Posts:
    440
    You don't need it to run on the main thread, you just need to disable burst on the job. Remove [BurstCompile] from the job and you should be able to call Debug.Log from inside it even if it's not running on the main thread.
     
  7. Mr-Mechanical

    Mr-Mechanical

    Joined:
    May 31, 2015
    Posts:
    507
    Nice! Elegant solution. Thanks a lot!
     
  8. bobdrejones

    bobdrejones

    Joined:
    Apr 9, 2023
    Posts:
    1
    You can easily
    using UnityEngine;
    and when logging say
    UnityEngine.Debug.Log("Hello world");
     
    Mr-Mechanical likes this.