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?

エラー対処 Assertion failed on expression: 'IsFinite

Posted at

Assertion failed on expression: 'IsFiniteのエラーが出た時の対処法

unityでScriptsにも異常がなく、「さあ、デバック開始、ポチっ」と再生モードに入るとき、
以下のようなエラーが大量に出続けることがあります。

Assertion failed on expression: 'IsFinite(distanceForSort)'
Assertion failed on expression: 'IsFinite(distanceAlongView)'

エラー文も短く、どこに問題があるか特定するのが非常に困難ですが、私のスクリプトの例で対処した方法を備忘録として残します。

原因と解決

以下のスクリプトに原因がありました。

private void Execute(Entity entity, ref TargetEntity targetEntity, LocalTransform transform,
            in EnemySearchRange targetRadius, ref UnitBrain brain, [ChunkIndexInQuery] int sortKey)
        {

            if (brain.LastEnemySearchTime <= currentTime + brain.EnemySearchCooldownTime) return; //クールダウンタイム中ならリターン

一番下の行のIf節が、永遠にTrueが返ってくる構文になっていました。
※本当はcurrentTime = (float)SystemAPI.Time.ElapsedTimeで、時間経過とともにTrueになったりFalseになったりするscriptにしたかったのですが、間違っていました。
エラーにはならない内容だけど、間違ってるよ、っていうのを教えてくれていたみたいです。

以下のように直して、エラーはでなくなりました。

if (brain.LastEnemySearchTime + brain.EnemySearchCooldownTime > currentTime ) return; //クールダウンタイム中ならリターン

エラーを吐き出すなら、原因となるスクリプトの場所ぐらいは教えてほしいですね。

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?