Is there a way to use Debug.Log within a foreach loop in a SystemBase and not get errors?

How are people checking real time data changes in a foreach loop in a SystemBase?

I assume that is burst error.
Just disable burst in menu, or remove burst attribute above the job.
In case of Entities.Foreach, just add .WithouthBurst ()

1 Like

Debug.Log works fine in burst jobs, no reason to disable it

https://docs.unity3d.com/Packages/com.unity.burst@1.4/manual/docs/CSharpLanguageSupport_Lang.html#partial-support-for-strings-and-debuglog

3 Likes

It works, but it will throw error, if string is not fixed. Something along with line

1 Like

If you’re looking to burst logs and are building the logged string from variables, you must use string interpolation or string.Format instead of concatenation. And you may only interpolate the types specified in the burst documentation (also linked above): Language Support | Burst | 1.4.11

I suggest reading the documentation, but here’s a short example. You may not write this:

Debug.Log("MyVariable equals " + myVariable);```

You may however write this:
```int myVariable = 10;
Debug.Log($"MyVariable equals {myVariable}");```
2 Likes

It will not throw any errors if you do it properly (using string interpolation or format) as explained by Zec_
Not doing it properly is an error and your job won’t burst compile.

1 Like

Note, starting from Burst 1.4:

This was re-enabled 2 previews later in [1.4.0-preview.3] - 2020-08-06

Okay sorry I missed that one in the change log. Both the 1.4 and 1.5 documentations are still listing it as a known issue, so I didn’t even bother using it much.