コードインスペクション:'foreach' 構造はサポートされていません
このインスペクションは、 バーストコンパイラー(英語)によってコンパイルされたコード内の foreach ループを報告します。
Burst は、ネイティブコンテナーなど、Burst と互換性のあるデータを反復処理する場合でも、 foreach 構造をサポートしていません。
サンプル
この例では、 foreach ループを使用して、Burst コンパイルされたジョブ内の NativeArray<int> を反復処理しています。 これはサポートされていないため、警告が表示されます。
using Unity.Burst;
using Unity.Collections;
using Unity.Jobs;
[BurstCompile]
public struct ExampleJob : IJob
{
public NativeArray<int> values;
public void Execute()
{
// Reported: foreach is not supported in Burst
foreach (var value in values)
{
}
}
}
using Unity.Burst;
using Unity.Collections;
using Unity.Jobs;
[BurstCompile]
public struct ExampleJob : IJob
{
public NativeArray<int> values;
public void Execute()
{
// Correct: Replace foreach with an index-based loop
for (var i = 0; i < values.Length; i++)
{
var value = values[i];
}
}
}
2026 年 6 月 12 日