Microsoft.Unity.Analyzers icon indicating copy to clipboard operation
Microsoft.Unity.Analyzers copied to clipboard

Recommend WithoutBurst() when Entity query contains code that would generate an error with Burst

Open therealjohn opened this issue 5 years ago • 1 comments

Problem statement

With the new Entity Component System (ECS), users can write code that is not compatible with the Burst compiler and it causes a runtime error.

The user needs to change their code to be Burst compatible, but if that's not possible or desirable, the WithoutBurst() method is recommended to exclude the code from Burst compilation.

Consider code like this in a SystemBase subclass's OnUpdate() method:

Entities.ForEach((ref Translation translation) =>
{
       var speed = Test.instance.speed; // reads a value from a static singleton class
       // Do something with speed
).Run();

Code like this will generate an error at runtime like:

Burst error BC1016: The managed function MyProject.Test.get_instance() is not supported.

Proposed solution

Modifying the code to this is an acceptable workaround if the user desires to use the singleton code as-is.

Entities.ForEach((ref Translation translation) =>
{
       var speed = Test.instance.speed; // reads a value from a static singleton class
       // Do something with speed
).WithoutBurst().Run();

therealjohn avatar Jul 16 '20 15:07 therealjohn

Automatically adding "help wanted" tag for stale issues identified as good community contribution opportunities

sailro avatar Apr 26 '21 22:04 sailro