Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by elwhywhy · Dec 05, 2016 at 11:54 AM · animatoranimator controlleranimationclipblend treesetfloat

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.

alt text

unityscreenshot.png (108.5 kB)
unityscreenshot2.png (109.1 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges