Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 ChefBaas · May 15, 2020 at 10:51 AM · animatoreditor-scriptinganimator controllersave scene

Animator.parameterCount returns 0 after saving project in editor

I'm trying to create an editor script which displays an animator's parameters. However, as soon as I save my project (after making any change), animator.parameterCount returns 0. A warning also appears saying Animator is not playing an AnimatorController. The warning references UnityEngine.Animator:get_parameterCount() specifically as the source of the warning.

I did an isolated test using the following script:

 [CustomEditor(typeof(Animator))]
 public class testScript : Editor
 {
     private Animator anim; 
 
     private void OnEnable()
     {
         anim = (Animator)target;
     }
 
     public override void OnInspectorGUI()
     {
         base.OnInspectorGUI();
 
         Debug.LogFormat("{0} - {1}", anim.name, anim.parameterCount);
         serializedObject.ApplyModifiedProperties();
     }
 }

This This is my isolated scene setup in a new, clean project. You can see in the console that initially the correct number of parameters were printed. Then I made a simple change, saved the project and both the warning and the second print popped up immediately.

Note that in the actual project the animator does have an avatar, states, everything, but the exact same behaviour occurs.

Does anyone know whether I'm doing something wrong? Am I not supposed to be able to access the parameterCount outside playmode?

parametercountquestion.png (197.8 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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by _tink_ · Oct 08, 2021 at 10:01 AM

I have stumbled upon the exact same problem. Initially, I have a correct number of parameters and after adding or deleting one, Animator.parameters return zero and a warning pops up. What resolved it, was "turn it off and on" approach:

 animator.enabled = false;
 animator.enabled = true;
 
 Debug.Log("Parameters count: {animator.parameterCount}");
 ...
Comment
Add comment · Show 4 · Share
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
avatar image ChefBaas · Oct 11, 2021 at 08:48 AM 0
Share

Ah, that's interesting! I don't think I have the project anymore to check whether it works for me, but I could easily recreate it. What version of Unity are you using? Perhaps that has something to do with it as well. I believe I was using Unity 2019.3 when I posted this.

avatar image _tink_ ChefBaas · Oct 11, 2021 at 08:56 AM 0
Share

I am using Unity 2020.3.11f1

avatar image ChefBaas _tink_ · Oct 11, 2021 at 08:59 AM 0
Share

Thanks, I'll do some tests with your proposed solution later this week and post my findings.

Show more comments

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

171 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to move Animation Clips into Animator Controller? 1 Answer

Effects of gameobject.setActive(false) on the animator. 2 Answers

SetTrigger not working 2 Answers

Animator.GotoState: State could not be found error fix? 0 Answers

spawns without controller-: Object reference not set to an instance of an object--but i swear it is! 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