代码检查:不支持加载托管类型
此检查会报告在 Burst 编译代码中读取托管类型值的情况。
通常当 Burst 代码读取类、接口、数组或其他托管类型的字段、变量或属性时会发生此问题。 在加载如 SharedStatic.GetOrCreate 这类 API 的 System.Type 值时,也可能出现同样的警告。
示例
在此示例中, data 字段是托管类类型。 在 Burst 编译的作业中读取它是不被支持的。
using Unity.Burst;
using Unity.Jobs;
public class ExampleData
{
}
[BurstCompile]
public struct ExampleJob : IJob
{
private static ExampleData data = new ExampleData();
public void Execute()
{
// Reported: loading a managed type is not supported in Burst
var value = data;
}
}
using Unity.Burst;
using Unity.Jobs;
public struct ExampleData
{
public int value;
}
[BurstCompile]
public struct ExampleJob : IJob
{
public ExampleData data;
public void Execute()
{
// Correct: Use unmanaged structs or native containers
var value = data.value;
}
}
快速修复
此检查不提供专用的快速修复。 请手动将托管值替换为 Burst 兼容的数据以解决此问题。
2026年 5月 8日