1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【Unity】AnimationClip.SampleAnimation には Animator コンポーネントが必要

Posted at

本記事で述べたいことは題記ですべてなのですが、やや混乱する挙動があったので記事に残します。

はじめに

AnimationClip には SampleAnimation という API があります。
これは AnimationClip 側からゲームオブジェクトにアニメーションを適用できるという少し変わった機能の関数です。

ドキュメントではパフォーマンスの点から代わりに Animation.Play を使うのが推奨と書いてありますが、それでもやむを得ず使いたい場面がありました。
エディタで実装して動作確認ヨシ!と思ってビルドしたところなぜか動かなくなり、ちょっとつまづくことになったわけです。

エディタでは Animator がなくても動く

これが引っかかってしまった最大の原因なのですが、Unity エディタ上では Animator がなくても目的のアニメーションが動きます。
そのため、特に何もつけないまま開発が進みます…。

image.png

image.png

ビルドでは Animator がないと動かない

そしてビルドした結果は動きません😭1

image.png

image.png

補足

この件について不具合っぽく見えたのでバグレポートしたところ、仕様とのことでした。ドキュメント作成の方々に伝えてくれたそうなので、いずれドキュメントに追記されるんじゃないかなーと思いますが、現状使用する場合は必ず Animator を一緒に付けるようにしましょう。

  1. Windows Standalone しか見てないので他プラットフォームではもしかしたら動くかもしれません。

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?