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 /
  • Help Room /
avatar image
0
Question by marrowick · Mar 15, 2016 at 05:28 PM · animationjumpnullreferenceexception

Animation issue

So I'm trying to learn ow to animate a character for use. After trying to assign "IsJumping" to "Jump" how ever it comes up with this error. "NullReferenceException: Object reference not set to to an instance of an object AnimationController.Update() (at Assets/AnimationController .cs:17)".

Here is the code. As stated in the error the line in question is line 17.

using UnityEngine; using System.Collections;

public class AnimationController : MonoBehaviour {

 static Animator animator;

 void start ()
 {
     animator = GetComponent<Animator>();
 }

 void Update ()
 {
     if(Input.GetButtonDown("Jump"))
     {
         animator.SetTrigger("IsJumping");
     }
 }

}

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
0

Answer by Zoogyburger · Mar 15, 2016 at 05:38 PM

In your animator are you sure you have that Trigger: "IsJumping" spelled exactly the same?

Also, you can just declare your animator by

 Animator animator;

If this doesn't work, notify me and I will tell you how to make a bool instead.

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 marrowick · Mar 15, 2016 at 06:45 PM

Yes, every character is exactly the same, I also switched the declaration to what you suggested, neither worked.

Comment
Add comment · Show 12 · 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 Zoogyburger · Mar 15, 2016 at 07:06 PM 0
Share

Quick try replacing line 10 with:

 if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Space))
avatar image marrowick Zoogyburger · Mar 15, 2016 at 11:00 PM 0
Share

Still nothing, also slight change. It didn't render all the code, so the error isn't line 17, it's line 10 on here.

avatar image Zoogyburger · Mar 15, 2016 at 11:33 PM 0
Share

Just tried your code and it works for me. The two things that I can think of that would set off a "NullReferenceException" is either you don't have an Input for "Jump" or your animator isn't assigned in your Inspector. So click on your player. In the Inspector make sure he has an Animator Component and the right animation controller is assigned in that Animator. Next, go to Edit at the top left corner of the window and go to Project Settings, Input. Look at your Inspector and check if the Jump is assigned or is right button etc.

avatar image marrowick Zoogyburger · Mar 15, 2016 at 11:50 PM 0
Share

The Animator is assigned. And "Jump" is assigned to "Space". The exact input settings are as below.

Note: Anything left out is blank.

Name: Jump Positive Button: Space Gravity: 1000 Dead: 0.001 Sensitivity: 1000 Type: $$anonymous$$ey or $$anonymous$$ousebutton Axis: X axis Joy Num: Get $$anonymous$$otion from all Joysticks

avatar image Zoogyburger · Mar 16, 2016 at 03:06 AM 0
Share

All of that is just what I got except my positive button is joystick button 3 but I don't think changing the positive button is going to help you. In your animation controller you should have a transition from your regular state to your jump state and on that transition the Conditions should be IsJumping. If this still won't work I'll tell you how to use a bool.

avatar image marrowick Zoogyburger · Mar 16, 2016 at 01:47 PM 0
Share

That didn't work either. :(

avatar image Zoogyburger · Mar 16, 2016 at 05:33 PM 0
Share

In your animation controller go to Parameters and Create a new bool called Jumping. On the transition that goes from your regular state to your jump state make the Conditions Jumping, true. In your script replace line 10 with the following line:

 anim.SetBool("Jumping", true);
avatar image marrowick Zoogyburger · Mar 17, 2016 at 12:43 AM 0
Share

Nope, still the same issue.

avatar image Zoogyburger · Mar 17, 2016 at 03:15 AM 0
Share

So your code is exactly this:

  Animator animator;
 
  void start ()
  {
      animator = GetComponent<Animator>();
  }
  void Update ()
  {
      if(Input.GetButtonDown("Jump"))
      {
          animator.SetBool("Jumping", true);
      }
  }
avatar image marrowick Zoogyburger · Mar 17, 2016 at 01:18 PM 0
Share

Double checked, yes.

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

84 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

Related Questions

How do/should I make my character jump? 1 Answer

I am slowly falling down with the jump animation 4 Answers

Jump animation delayed when on a higher platform. 0 Answers

How to play attack animation multiple times with mechanim 0 Answers

AgrumentNullException And NullReferenceException on animating [Video] 0 Answers


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