以下のエラーが出た際の対処法について
System.ArgumentNullException: e This Exception was thrown from a job compiled with Burst, which has limited exception support.
このエラーは直接的な原因がかなり分かりずらいです。
根本的な原因は不明な部分もありますが、ひとまず問題が起きた対象スクリプトと対処法だけは、メモを残します。
問題のスクリプト
[BurstCompile]
[WithAll(typeof(Simulate))]
partial struct ShortDistanceAttackEnemyJob : IJobEntity
{
public float currentTime;
public EntityCommandBuffer.ParallelWriter ecb;
public void Execute(Entity entity, TargetEntity targetEntity, ref CharactorAttackProperties attackProperties,
ref UnitBrain brain, ShortDistanceAttack shortAttack, [ChunkIndexInQuery] int sortKey)
{
ecb.AddComponent(sortKey, entity, new CharactorAttackProperties { LastAttackTime = currentTime });
かなり省略して書いていますが、要はExcute内でAddComponentして、特定のcomponent内の変数設定すると、問題が発生しました。
仕方がないので、暫定的に以下のように記述することで、解決させました。
[BurstCompile]
[WithAll(typeof(Simulate))]
public partial struct ShortDistanceAttackEnemyJob : IJobEntity
{
public float currentTime;
public EntityCommandBuffer.ParallelWriter ecb;
public void Execute(Entity entity, TargetEntity targetEntity, CharactorAttackProperties attackProperties,
ref UnitBrain brain, ShortDistanceAttack shortAttack, [ChunkIndexInQuery] int sortKey) //entityは攻撃するEntity
{
ecb.AddComponent(sortKey, entity, new AttackLastTime { Value = currentTime });
別のコンポーネントを作成して、CurrrentTimeを格納しています。
あまり納得がいかないですが、これなら問題なく動くのと、他に解決方法が思い浮かばないです...
原因と解決方法が分かったら、本記事もアップデートしようと思います。