前提・実現したいこと
AnimatorState.motionにAnimationClipを代入したらNullになってしまう現象をなんとかしたい。
発生している問題
AnimatorState.motionにAnimationClipを代入したら何故かNoneになっていた。
Debug.Logで確認したらNullになっていた。
該当のソースコード
clipにはちゃんとAnimationClipがアタッチされている。
C#
1using UnityEngine; 2using UnityEditor.Animations; 3 4public class Test : MonoBehaviour 5{ 6 [SerializeField] 7 AnimationClip clip; 8 9 void Start() 10 { 11 Animator animator = gameObject.AddComponent<Animator>(); 12 AnimatorController animatorController = new AnimatorController(); 13 animatorController.AddLayer("base Layer"); 14 AnimatorState animatorstate = new AnimatorState(); 15 animatorstate.motion = clip; 16 animatorController.layers[0].stateMachine.AddState(animatorstate, new Vector3(0,0,0)); 17 animator.runtimeAnimatorController = animatorController; 18 Debug.Log(animatorstate.motion); 19 } 20}
補足情報
Unity 2019.2.10f1
あなたの回答
tips
プレビュー