PLEASE help, the Anim.SetBool or Anim.SetFloat s are sending tons of errors!
hi, i need help with fixing this, i dont know whats going on, about 1 or 2 months i was using the same script and having animators running well, but now i turned the (UseAnimator) variable "on" in inspector, and tested it, it gave me tons of null errors! i swear i attached the animator through Update and the parameters exists in the animator, just when the parameter has to work, like sitting on ground, it gives null errors, the script line of Animator:
private function AnimatorManager ()
{
if(UseAnimator)
{
if(UsePower)
{
Anim.SetFloat("Power",Power);
}
Anim.SetFloat("Vertical",Input.GetAxis("Vertical") && GroundChecks.Grounded && Controllable);
Anim.SetFloat("Horizontal",Input.GetAxis("Horizontal") && GroundChecks.Grounded && Controllable);
Anim.SetBool("Run",Input.GetButton("Run") && GroundChecks.Grounded && Controllable);
Anim.SetBool("Jump",Input.GetButton("Jump") && GroundChecks.Grounded && Controllable);
Anim.SetBool("Crouch",Crouch && GroundChecks.Grounded && Controllable);
Anim.SetBool("Inside Water",InsideWater && Controllable);
Anim.SetBool("Grounded",GroundChecks.Grounded && Controllable);
Anim.SetBool("Near Fall Grounded",GroundChecks.NearFallGrounded && Controllable);
Anim.SetBool("Mid Fall Grounded",GroundChecks.MidFallGrounded && Controllable);
Anim.SetBool("Far Fall Grounded",GroundChecks.FarFallGrounded && Controllable);
}
}
Also the AnimatorManager function called in function update! but i dont know whats wrong with these lines of code! The Error Message:(its one error that i pasted it here, actually they're about 9 errors) NullReferenceException: Object reference not set to an instance of an object PlayerController.AnimatorManager () (at Assets/Player Controller/Scripts/PlayerController.js:165) PlayerController.Update () (at Assets/Player Controller/Scripts/PlayerController.js:75)
is there a way to fix it? i appreciate any answers!
If it says "Object reference not set to an instance of an object", you can be sure that this is exactly the problem.
But as you posted only a part of the code, so we can't know which line number refers to which code line, this is all that can be said.
actually for example, the line says: Anim.SetFloat("Vertical",Input.GetAxis("Vertical")); when i press forward or backward, the error instantly appears, and also when i press jump button, it appears another error , when i press left or right, it appears another one, so it means each of them doesnt work for no reason :(
Anim.SetFloat("Vertical",Input.GetAxis("Vertical") && GroundChecks.Grounded && Controllable);
If that line shows the above mentioned error, it can only have one of two reasons: Either "Anim" or "GroundChecks" is null. (Theoretically "Input" could be null, too. But it's highly unlikely, so we'll ignore that).
Answer by gtav225 · Jan 19, 2017 at 12:45 PM
The Error Occurred because of unity version maybe, yesterday i Updated Unity to 5.5 and the error gone! im enjoying playing around like GTA 5, thanks for your time and answers :D