代码检查:Burst:String.Format(format, ...) 实参类型无效
该检查会报告传递给 string.Format() 并在 Burst 编译器编译的代码中不受支持的实参类型。
在 Burst 中, string.Format 只支持有限的实设置。 如果其中一个格式设置实参是托管类型,甚至是 string ,则此检查会发出警告,因为 Burst 在此情况下只支持值类型实参。 托管对象,如 CultureInfo ,也会触发此警告。
示例
在此示例中,将字符串实参传递给 string.Format。 在 Burst 编译的代码中不支持此操作。
using Unity.Burst;
using Unity.Jobs;
[BurstCompile]
public struct ExampleJob : IJob
{
public void Execute()
{
// Reported: String arguments are not supported in string.Format within Burst
string.Format("Player: {0}", "Alice");
}
}
using Unity.Burst;
using Unity.Jobs;
[BurstCompile]
public struct ExampleJob : IJob
{
public int score;
public void Execute()
{
// Correct: Use Burst-compatible value types
string.Format("Score: {0}", score);
}
}
快速修复
此检查不提供专用快速修复。 可通过将不受支持的格式设置实参替换为 Burst 兼容的值类型,或将格式设置移出 Burst 编译代码来手动修复。
2026年 5月 8日