代码检查:Burst:变量解析为 System.String,这可能导致在 Burst 编译的调用堆栈中产生无效的托管方法调用。
该检查会报告由 Burst 编译器 编译的代码中本地 var 声明解析为 System.String 的情况。
Burst 不支持在本地变量中安全地使用常规托管字符串。 当类型推断将本地变量转换为 string 并用于 [BurstCompile] 方法或作业时,将触发此检查。
示例
在此示例中, var text 声明被推断为 string。 快速修复会自动将该声明转换为显式的 FixedString... 类型。
using Unity.Burst;
using Unity.Jobs;
[BurstCompile]
public struct ExampleJob : IJob
{
public void Execute()
{
// Reported: Local var inferred as string is not supported in Burst
var text = "Hello";
}
}
using Unity.Burst;
using Unity.Collections;
using Unity.Jobs;
[BurstCompile]
public struct ExampleJob : IJob
{
public void Execute()
{
// After fix: Use Burst-compatible FixedString types
FixedString32Bytes text = "Hello";
}
}
快速修复
快速修复会将声明转换为显式的 FixedString... 类型(如 FixedString32Bytes、 FixedString64Bytes 等),以保持代码对 Burst 兼容,并避免推断为 string 的本地变量。
2026年 5月 8日