Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
1
Question by The Ghost · Jun 30, 2013 at 02:50 AM · animationerrormovementmecaniminitialization

Help with Animator has not been initialized error

Every time I try to run the game I get the error: Animator has not been initialized. UnityEngine.Animator:SetFloat(String, Single)

Here's the portion it's calling the error on:

anim.SetFloat("Speed", speed); anim.SetFloat("Move", isMoving);

And here's the whole script:

 public class PlayerMovement : MonoBehaviour
     {
         public float speed = 1f;
         public Vector3 touchPoint;
         public float isMoving = 1f;
         
     public Animator anim; 
     void Update()
     {
         anim.SetFloat("Speed", speed);
         anim.SetFloat("Move", isMoving);
         
         // Lerps to the last position touched, going to have to modify this
         // to only work when tapped not hold cause shooting will be hold.
         
         if (Input.touchCount > 0 )
         {
             // Shoots a ray where you touched the screen
             RaycastHit hit;
             // There was an error before. The tag must be main camera.
             Ray ray = Camera.main.ScreenPointToRay(Input.touches[0].position);
             
             if (Physics.Raycast(ray, out hit, Mathf.Infinity))
             {
                 // converts the touch point to unitys 3d worldspace Vector3
                 touchPoint = hit.point;                                                                         
             }
         }
         MoveToPos(touchPoint);
         //isMoving = (Mathf.Abs(transform.position.z - touchPoint.z)* 10);
     }
     void MoveToPos(Vector3 touchPoint)
     {          
         gameObject.transform.position = Vector3.Lerp(gameObject.transform.position, new Vector3(touchPoint.x, 10, touchPoint.z), speed * Time.deltaTime);    // LAWL this had to be z even tho im using y for droid , wasted alot of time on that.  
         //gameObject.transform.LookAt(touchpoint);
     }
 }
 
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

5 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by HelloRainbow · Nov 10, 2015 at 05:35 PM

Animator not ready in this frame, use it in next frame. you can use coroutine to do this:

yield return new WaitForEndOfFrame(); obj.GetComponent().SetBool("run", true);

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
1

Answer by mscarter · Jan 30, 2014 at 06:38 PM

I had this error and found that the controller reference on my Animator component had been set to null somehow. Re-adding the reference to the Controller fixed the issue.

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
1

Answer by KCoulombe · Aug 06, 2014 at 08:29 PM

you defined "anim" but never set it to anything.

try:

 void Start()
 {
     anim = GetComponent<Animator>();
 }

This will set "anim" to the Animator component on the game object.

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
-1

Answer by SuperBrian69 · Nov 14, 2013 at 11:57 PM

I had this error and struggled for a few hours, but then I added:

"anim = GetComponentAnimator>();"

in the update function and it seems to work, but I am not sure why...

Comment
Add comment · Show 1 · 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 d12frosted · Aug 06, 2014 at 07:45 PM 0
Share

Not very good solution. Not at every update Unity will seek for Animator component. And this can dramatically slow your game.

avatar image
0

Answer by m_danish_s · Jul 01, 2015 at 10:39 AM

I had the same issue with unity 5.0 but this was due to my stupidity.

Make sure you are referencing to the correct object. I had object referenced from inspector to my script and I was calling getComponent on that object. For testing I just replaced the object which didn't have Animator component attached to it.

Comment
Add comment · Show 1 · 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 shadowpuppet · Jan 12, 2018 at 10:29 PM 0
Share

I get 999+ caution warnings - not errors but the yield sign warning. and no logic for most of them . I have a SetTrigger call in an OnTrigger Enter. Cleasrly the animator should have initialized in the start or even an awake function. i mean I have not even asked the animator to do anything yet and unity is telling me that line of code is a "caution" because the animator has not been initialized. I have been ignoring it because it works - none of my 999+ "cautoions" break the game so what is the deal

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

20 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

Related Questions

Mecanim blend moves character? 1 Answer

mecanim and fingers error 0 Answers

Animate mecanim character only from script 1 Answer

Third-person character animations based on World-relative input and Y-rotation (looking at mouse position) 1 Answer

Can i use mecanim animator while using legacy? 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