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 ApolloVision · Mar 03, 2014 at 11:41 AM · javascriptmovementaudioprogramming

ArgumentNullException: Argument cannot be null

I keep getting the error ArgumentNullException: Argument cannot be null. of my script. Its basically teling a gameObject (I named "Enemy") with a CharacterController to play sound whenever it moves horizontally and/or vertically.

 var footsteps : AudioClip;
 var CharacterController;
 
 
 
 function Start() 
 {
    audio.clip = footsteps;
     audio.loop = true;
 }
 
 
 
 
 function Update()
 
 {
 
 
 
 
    if (CharacterController("Horizontal") != 0 || CharacterController("Vertical") != 0)
 
 
     {
 
 
 
 
 
       if(!audio.isPlaying)
 
           audio.Play();
 
 
    }
 
    
 
    else if(CharacterController("Horizontal") == 0 && CharacterController("Vertical") == 0)
 
 
        audio.Stop();
 
 
 }
 

What's more wierd is despite of the error I could still play the game just fine but it is annoying that whenever I look at my console box for debugging this same error display every frame.

EDIT: For more detail: I am trying to play a footstep audio clip whenever the gameObject (the Enemy) moves. It works but this error always show up in my console box.

Comment
Add comment · Show 5
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 perchik · Mar 03, 2014 at 07:25 PM 0
Share

You have a variable named CharacterController which is also a type, and is probably not a good idea.

avatar image Dblfstr · Mar 03, 2014 at 07:52 PM 0
Share

What line is giving the error? Do you have an audiosource attached to your gameObject? Is this going to be the only audio that is played by this gameobject?

avatar image ApolloVision · Mar 04, 2014 at 05:12 AM 0
Share

It is line 24 I believe. I only have one audio clip at the moment. it is just a few seconds of footstep sounds looped.

This works with my Player, so when I move horizontally or vertically it plays the adui, but not with the Enemy AI.

avatar image ApolloVision · Mar 04, 2014 at 05:21 AM 0
Share

It is line 24 I believe. I only have one audio clip at the moment. it is just a few seconds of footstep sounds looped.

This works with my Player, so when I move horizontally or vertically it plays the audio, but not with the Enemy AI.

I'm basically trying to tell the object that whenever it moves horizontally or vertically, play the audio.

avatar image Benproductions1 · Mar 04, 2014 at 10:25 AM 1
Share

Your problems:

  1. Your variable CharacterController has no type and is therefore of type: Object by default.

  2. There is a name conflict between your variable CharacterController and the UnityEngine type: CharacterController

  3. You are calling your variable. Unless your variable is a (non-behaviour) type or a function you should (and cannot) call it.

    How to fix it:

Add #pragma strict to the top of your file and fix the compiler errors (`strict` gives very good recommendations for error fixing)

Also

Please don't leave so much white-space in your question, it's really annoying to read.

0 Replies

· Add your reply
  • Sort: 

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

23 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

Related Questions

Multiple Cars not working 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Setting Scroll View Width GUILayout 1 Answer

Move Object Smoothly 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