代码检查:调试日志函数只接受字符串
当记录的值不是字符串时,在由 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日