0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

エラー対処 System.ArgumentNullException: e

Posted at

以下のエラーが出た際の対処法について

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を格納しています。
あまり納得がいかないですが、これなら問題なく動くのと、他に解決方法が思い浮かばないです...
原因と解決方法が分かったら、本記事もアップデートしようと思います。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?