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
0
Question by ska88 · Jan 19, 2014 at 06:59 PM · 2d2d controller2d-tutorial

2d controller script won't recognize Animator

hi guys, i need your help:

i was following this tutorial Live Training 16 Dec 2013 - 2D Character Controllers

All went good till 45:30 when it's time to insert a referment to Animator in my C# script. Before that all was fine:

1) My animations are working properly if i try them in the animation's window

2) The script is a component inside character, I'm sure about this because if i try the code until here it works fine, i can move my char and all.

3) The animator is a component inside character as well, i verified this pressing play and watching at my character properly moving how the idle animation is supposed to make him move.

Now, from 45:30 i got a problem.

4)I declare an Animator variable called anim and all works fine, obviously.

5)I try to make anim refer to my Animator writing this in Start(): "anim.GetComponent< Animator >();" (left some space after the < and the > here but it's written properly in the code)

6) try to add a modifier for the Speed parameter writing this in FixedUpdate(): anim.SetFloat ("Speed", Mathf.Abs(move));

So i do everything he does, also i got no errors in the code. But then this happens when i start the scene, which immediatly pause:

"NullReferenceException UnityEngine.Component.GetComponent[Animator] () (at C:/BuildAgent/work/d3d49558e4d408f4/artifacts/EditorGenerated/UnityEngineComponent.cs:187)"
refering to the line in point 5

"NullReferenceException UnityEngine.Animator.SetFloat (System.String name, Single value) (at C:/BuildAgent/work/d3d49558e4d408f4/artifacts/EditorGenerated/AnimatorBindings.cs:176)"
refering to the line in point 6

As far as i get the script won't recognize the animator inside character, even if they both are inside it. I tried to create a brand new animator and script but i got the same problem so I'm probably missing something and i'll be glad if you could help me.

Tyvm for your attention, sorry if i wrote so much

Peace

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 ska88 · Jan 20, 2014 at 12:01 AM

Solved myself. This was the error:

I wrote "anim.GetComponent< Animator >();" instead of "anim = GetComponent< Animator >();"

If this ever happens to anyone else, hope this thread could help,

cya guys

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

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

18 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

Related Questions

how to make 2D sprites skeletal Movements 1 Answer

Collision with grid based movement 0 Answers

2D Platformer Character Controller 1 Answer

2D Animation does not start 1 Answer

ex2d with physics ? 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