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 Rosscoe3 · Dec 10, 2015 at 06:28 AM · animationanimatoranimator controllerinitialization

Animator has not been initialized!!!!!! Help!!

So i've been going through forms trying to figuire this problem out.. but haven't been able to fix it yet :P So here's my problem.. I have 3 objects that use animators and are found on start of the scene.. the first runthrough is fine.. and works perfectly.. But I have a restart function in my game.. and when i restart the level.. the animation is at its previously final state.. and i get the error: "Animator has not been initialized."

here's the code:

using UnityEngine; using System.Collections;

public class playScript : MonoBehaviour {

 public bool playClicked = false;
 public GameObject score;
 public GameObject specials;
 public GameObject pauseButton;
 public GameObject deathMessage;
 public GameObject endScore;
 //public GameObject playButton;

 public PlayerSpawn spawnPlayer;

 Animator specialBarAnimator;
 Animator scoreAnimator;
 Animator pauseAnimator;

 void Awake ()
 {
 
 }

 void Start ()
 {

     playClicked = false;
     score.SetActive (false);
     specials.SetActive (false);
     pauseButton.SetActive (false);
     StartCoroutine(Play());
     deathMessage.SetActive (false);
     endScore.SetActive (false);

 }

 void Update ()
 {
 
     specialBarAnimator = specials.GetComponent<Animator>();
     scoreAnimator = score.GetComponent<Animator>();
     pauseAnimator = pauseButton.GetComponent<Animator>();

     if (PlayerScript.dead)
     {
         specialBarAnimator.SetTrigger ("Dead");
         scoreAnimator.SetTrigger ("Dead");
         pauseAnimator.SetTrigger ("Dead");
         deathMessage.SetActive (true);
         endScore.SetActive (true);
     }
 }

 IEnumerator Play () 
 {
     yield return new WaitForSeconds(2);

     playClicked = true;

     score.SetActive (true);
     specials.SetActive (true);
     pauseButton.SetActive (true);

     spawnPlayer.CharacterSpawn();
 }

}

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

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by GiyomuGames · Dec 10, 2015 at 07:04 AM

You are probably trying to use the animators while your object is inactive.

Comment
Add comment · 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
0

Answer by BackslashOllie · Dec 10, 2015 at 05:20 PM

Do you really need to be setting your animator variables every frame?

I would suggest putting these three lines into your Awake or Start functions before setting the GameObjects to inactive:

      specialBarAnimator = specials.GetComponent<Animator>();
      scoreAnimator = score.GetComponent<Animator>();
      pauseAnimator = pauseButton.GetComponent<Animator>();
Comment
Add comment · Show 2 · 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 Rosscoe3 · Dec 11, 2015 at 04:46 AM 0
Share

Oopps no i do not.. i put them into the start function.. but the same exact thing happened.. I also tried making them inactive when (PlayerScript.dead) was true.. but it says the Animator doesn't allow ".SetActive" methods to be used.. Any clue what to do?

avatar image BackslashOllie Rosscoe3 · Dec 12, 2015 at 09:07 PM 0
Share

I think Guidanel has got it in one. You just need to step through your code and see when your code is trying to call the animator whilst its gameobject is inactive.

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

47 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

Related Questions

Attempting to change AnimatorController during Runtime 0 Answers

Animator parameter does not pick the value of the animation curve with the same name 2 Answers

Wrap Mode in animator not working properly 0 Answers

Display additional animation on top of other animations 0 Answers

Animator Override Controller changed at runtime doesn't always play the animations correctly 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