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 SterlingStudios · Apr 27, 2014 at 04:12 PM · audiowatercompiler error

NullReferenceException Confusion

Hello. I have a footsteps script I found, but I have a problem. Every time my frame updates, I have a single NullReferenceException. This eats up a HUGE amount of my game's performance. Please help! Here the code:

 #pragma strict
 
 var inWater : boolean = false;
 var waterStepSound : AudioClip;
 
 var waterTimer : float = 0;
 var waterCool : float = 0.6;
 
 private var chMotor : CharacterMotor;
 private var controller : CharacterController;
 
 function Start()
 {
     chMotor = GetComponent(CharacterMotor);
     controller = GetComponent(CharacterController);
 }
 
 function Update()
 {
     if(controller.velocity.magnitude > 0 && Input.GetKey(KeyCode.LeftShift))
     {
         chMotor.movement.maxForwardSpeed = 10;
         chMotor.movement.maxSidewaysSpeed = 10;
     }
     
     else
     {    
         chMotor.movement.maxForwardSpeed = 7;
         chMotor.movement.maxSidewaysSpeed = 6;
     }
     
     if(controller.velocity.magnitude > 0 && inWater == true)
     {
         WaterSound();
     }
     
     if(controller.velocity.magnitude > 0 && Input.GetKey(KeyCode.LeftShift) && inWater == true)
     {
         waterCool = 0.4;
         WaterSound();
     }
     
     else
     {
         waterCool = 0.6;
     }
     
     if(waterTimer > 0)
     {
         waterTimer -= Time.deltaTime;
     }
     
     if(waterTimer < 0)
     {
         waterTimer = 0;
     }
 }
 
 function WaterSound()
 {
     if(waterTimer == 0)
     {
         audio.PlayOneShot(waterStepSound);
         waterTimer = waterCool;
     }
 }

And the other script it is working with:

 #pragma strict
 
 private var footsteps : PlayerFootsteps;
 
 function Start()
 {
     footsteps = GameObject.Find("First Person Controller").GetComponent(PlayerFootsteps);
 }
 
 function OnTriggerEnter (Col : Collider)
 {
     if(Col.gameObject.tag == "Player")
     {
         footsteps.inWater = true;
     }
 }
 
 function OnTriggerExit (Col : Collider)
 {
     if(Col.gameObject.tag == "Player")
     {
         footsteps.inWater = false;
     }
 }


                                                           
Comment
Add comment · Show 2
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 meat5000 ♦ · Apr 27, 2014 at 04:12 PM 0
Share

Please post the error

avatar image SterlingStudios · Apr 27, 2014 at 05:35 PM 0
Share

Ok. Here it is: NullReferenceException $$anonymous$$ovementscript.FixedUpdate () (at Assets/Footsteps.js:28) in the first script

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by KellyThomas · Apr 27, 2014 at 05:37 PM

It looks like chMotor is null when executing that line.

This would be the case is GetComponent(CharacterMotor) returns null in Start().

Is a CharacterMotor script attached to this GameObject? Is the script disabled?

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 SterlingStudios · Apr 27, 2014 at 07:55 PM 0
Share

Yes, a Character$$anonymous$$otor is attached to the GameObject. Is that messing it up?

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

22 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

Related Questions

Problems making an audio JumpScare 2 Answers

Audio not working With Compare Tag 0 Answers

pause a audio inside game 1 Answer

Audio Not working 1 Answer

How to reflect / bounce audio off of a 3D Object? 4 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