- Home /
Animator not playing a playable
I asked before but I think the post got withheld by moderators coz of not enough details.
I need to make a sprite animation. The player can change the colour of the hair, clothes, shoes, etc, of the sprites. Then those sprites get saved in assets/resources folder as a prefab. I also created a list of the prefabs, so I can easily access them in creating keyframes for animation.
The problems comes with animating the sprites. I used code examples from other post and just change their sprites to mine. I just wanted to test if my code was working before making all the sprite animations so my blend tree has only one child animation (walk.anim see script attached). Anyway, I tested out and the code compiles fine in Monodevelop, but Unity spams this error when I try testing out my game: Animator is not playing a playable. It says the problem is with anim.setfloat (line 68, see script attached).
I think the creation of animation and blend tree is not the problem. When I exit the game testing, the resource folder shows my blend tree the way I wanted it. I think anim.setfloat parameters cannot be accessed somehow.
  using UnityEngine;
  using System.Collections;
  using System.Collections.Generic;
  #if UNITY_EDITOR
  using UnityEditor;
  #endif
  
  public class donebutton : MonoBehaviour {
  
      //prefabstring is a list of paths to prefabs (example "Assets/Resources/1.prefab")
      public static List<string> prefabstring = new List<string> ();
  
      //list of prefabs
      public static List<GameObject> prefablist = new List<GameObject> ();
      Object prefab;
  
      // Use this for initialization
  
      void Start () {
              
          for (int a = 0; a < 14; a ++) {
  
              //locating prefab, stores the located prefab in prefab
              #if UNITY_EDITOR
              prefab = AssetDatabase.LoadAssetAtPath(prefabstring[a], typeof(Object));
              #endif
  
              //go is the prefab that is instantiated
              GameObject go = Instantiate (prefab) as GameObject;
  
              //disables the viewing of all prefabs and their childrens
              go.GetComponent<SpriteRenderer> ().enabled = false;
              for (int i = 0; i < go.transform.childCount; i++) {
                  go.transform.GetChild (i).GetComponent<SpriteRenderer> ().enabled = false;
              }
  
              //adding components to go(which is the instantiated prefab)
              go.AddComponent<playercontroller>();
              go.AddComponent<Animator> ();
              go.AddComponent<playeranimation>();
  
              //stores the instatiated prefabs in prefablist
              prefablist.Add (Instantiate (go, new Vector3 (0f, 0f, 0f), Quaternion.identity) as GameObject);
          }
          //I made one of the prefab visible. Nevermind I don't think you need to know this(and the stuff below) to solve the problem.
          instantiatedgoenabler (prefablist[0]);
  
      }
  
      void instantiatedgoenabler(GameObject newinstantiatedgo)
      {
          newinstantiatedgo.GetComponent<SpriteRenderer> ().enabled = true;
          for (int a = 0; a < newinstantiatedgo.transform.childCount; a++) {
              newinstantiatedgo.transform.GetChild (a).GetComponent<SpriteRenderer> ().enabled = true;
          }
      }
  using UnityEngine;
  using System.Collections;
  using System.Collections.Generic;
  #if UNITY_EDITOR
  using UnityEditor;
  #endif
  
  public class playeranimation : MonoBehaviour {
      //this script is to control all player animations. Has blendtree, animation and animator stuff.
  
      Animator anim; 
      // Use this for initialization
      void Start () {
          anim = GetComponent<Animator>();
          walkdown();
  
          var controller = UnityEditor.Animations.AnimatorController.CreateAnimatorControllerAtPath("Assets/Resources/Canblendtostate.controller");
          UnityEditor.Animations.BlendTree blendTree = new UnityEditor.Animations.BlendTree ();
          controller.AddParameter("ismoving", AnimatorControllerParameterType.Bool);
          controller.AddParameter("movex",  AnimatorControllerParameterType.Float);
          controller.AddParameter("movey", AnimatorControllerParameterType.Float);
          controller.AddParameter("lastmovex", AnimatorControllerParameterType.Float);
          controller.AddParameter("lastmovey", AnimatorControllerParameterType.Float);
          controller.CreateBlendTreeInController ("dunno", out blendTree, 0);
          blendTree.blendType = UnityEditor.Animations.BlendTreeType.SimpleDirectional2D;
          blendTree.name = "Blend Tree";
          blendTree.blendParameter = "movex";
          blendTree.blendParameterY = "movey";
          //below adds walk.anim(clips is a list that stores .anim, and clip[0] stores walk.anim) to blend tree... I think...
          //I think the new Vector2 is supposed to be the conditions for change in animation in blend tree.
          blendTree.AddChild (clips[0], new Vector2(0f, -1f));
      }
  
      //a list of clips for easy excess in Start function
      List<AnimationClip> clips = new List<AnimationClip> ();
  
      //Im very vague about this part onwards (especially the walkdown() part). I just used other people code as a template then substitute the variables with mine.
      //walkdown() is suppose to create animation clip of the player sprite walking down.
      EditorCurveBinding spritebind = new EditorCurveBinding ();
  
      void walkdown()
      {
          AnimationClip walk = new AnimationClip ();
          clips.Add (walk);
          walk.frameRate = 6;
  
          spritebind.type = typeof(SpriteRenderer);
  
          ObjectReferenceKeyframe[] walkdownkf = new ObjectReferenceKeyframe[2];
  
          walkdownkf [0] = new ObjectReferenceKeyframe ();
          walkdownkf [0].time = 3f;
          walkdownkf [0].value = donebutton.prefablist [1];
          walkdownkf [1] = new ObjectReferenceKeyframe ();
          walkdownkf [1].time = 3f;
          walkdownkf [1].value = donebutton.prefablist [2];
  
          AnimationUtility.SetObjectReferenceCurve (walk, spritebind, walkdownkf);
  
          AssetDatabase.CreateAsset (walk, "Assets/Resources/walk.anim");
          AssetDatabase.SaveAssets ();
          AssetDatabase.Refresh ();
      }
  // Update is called once per frame
      void Update () {
          //anim.SetFloat caused the Animator is not playing a playable... either that or there's something worng with my walk.anim
          anim.SetFloat ("movex", Input.GetAxisRaw("Horizontal"));
          anim.SetFloat ("movey", Input.GetAxisRaw("Vertical"));
      }
after I test the game once, canblendtostate and walk.anim showed up in my resources folder.

Your answer
 
 
             Follow this Question
Related Questions
2D: initial sprite idle animation playing too fast upon game initiation until I input movement keys? 1 Answer
AnimatorOverrideController not working 0 Answers
Velocity not changing value in Blend Tree 0 Answers
Blending animations for a bow with differing charges 1 Answer
How to move Animation Clips into Animator Controller? 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                