代码检查:不支持写入静态字段
Burst 不支持写入静态状态。 这种情况通常发生在 [BurstCompile] 作业或其他 Burst 编译方法中。
示例
在本例中, counter 字段被声明为 static。 在 执行 方法的 [BurstCompile] 作业中写入该字段是不被支持的。
using Unity.Burst;
using Unity.Jobs;
[BurstCompile]
public struct ExampleJob : IJob
{
private static int counter;
public void Execute()
{
// Reported: Writing to a static field is not supported
counter = 1;
}
}
using Unity.Burst;
using Unity.Jobs;
[BurstCompile]
public struct ExampleJob : IJob
{
public int counter;
public void Execute()
{
// Correct: Use instance fields or native containers instead
counter = 1;
}
}
快速修复
此检查不提供专用的快速修复。 手动修复:移除对静态字段的写入,并把状态移到 Burst 兼容的数据类型,例如实例字段、作业数据或受支持的原生容器中。
2026年 5月 8日