代码检查:调试日志函数只接受字符串。
当记录的值不是字符串时,如果在由 Burst 编译器编译的代码中调用 Debug.Log、 Debug.LogWarning 或 Debug.LogError ,会报告此检查。
Burst 调试日志仅接受普通字符串和支持的固定字符串。 直接记录数字、结构体或其他非字符串值将触发此检查,因为这会涉及隐式转换或装箱为托管对象。
示例
在此示例中,整数被直接传递给 Debug.Log。 在 Burst 编译代码中不支持此操作。
using Unity.Burst;
using Unity.Jobs;
using UnityEngine;
[BurstCompile]
public struct ExampleJob : IJob
{
public void Execute()
{
// Reported: Debug.Log argument must be a string or fixed string
Debug.Log(42);
}
}
using Unity.Burst;
using Unity.Collections;
using Unity.Jobs;
using UnityEngine;
[BurstCompile]
public struct ExampleJob : IJob
{
public void Execute()
{
// Pass a string or a Burst-compatible fixed string
FixedString128Bytes message = "Value: 42";
Debug.Log(message);
}
}
快速修复
此检查不提供专用的快速修复。 请手动将记录参数更改为字符串或固定字符串以修复。
2026年 5月 8日