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 /
avatar image
2
Question by RandomCharacters · Oct 09, 2015 at 04:23 PM · error message

There is no 'AudioSource' attached Error

I am getting this error but I have audio attached to it. I have deleted the component and even rebooted. Weird issue.

So here is the error: MissingComponentException: There is no 'AudioSource' attached to the "Input-Escape-MainMenu" game object, but a script is trying to access it. You probably need to add a AudioSource to the game object "Input-Escape-MainMenu". Or your script needs to check if the component is attached before using it. InputEscape+c__Iterator6.MoveNext () (at Assets/Extras Created/InputEscape.cs:47) UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator) InputEscape:Update() (at Assets/Extras Created/InputEscape.cs:40)

here is the code. It only gives the error after pressing the spacebar

 using UnityEngine;
 using System.Collections;
 ///////////////////////////////////////////////////////////////
 public class InputEscape : MonoBehaviour
 {
     ///////////////////////////////////////////////////////////////
     public GameObject mainMenuBtn;          //    quit button
     public GameObject nextBtn;                //    next button
     public GameObject overHeadBtn;          //    overhead button
 
     public GameObject effectNewBestScore;
 
     new AudioSource audio;
     public AudioClip menuSound51;
     ///////////////////////////////////////////////////////////////
     void Awake()
     {
         audio = GetComponent<AudioSource>();
 
         mainMenuBtn = GameObject.FindWithTag("MainMenuButton");        
         overHeadBtn = GameObject.FindWithTag("OverHeadButton");
         effectNewBestScore = GameObject.FindWithTag("BestScore");
 
         nextBtn = GameObject.FindWithTag("NextHoleButton");
     }
     ///////////////////////////////////////////////////////////////
     void Update ()
     {
         if (Input.GetKeyDown(KeyCode.Escape))
         {
             CanvasButtonsOnOff.fire1ButtonPressed = true;
 
             mainMenuBtn.SetActive(false);
             nextBtn.SetActive(false);
             overHeadBtn.SetActive(false);
 
             //destroy settings-1, settings-2.....courses
                 Destroy(GameObject.FindWithTag("settings-all"));
 
             StartCoroutine(WaitForMainMenu2());
         }
     }
     ////////////////////////////////////////////
     IEnumerator WaitForMainMenu2()
     {
         audio.PlayOneShot(menuSound51, 1f);
         while (audio.isPlaying == true)
         {
             yield return null;
         }
 
         effectNewBestScore.SetActive(false);
         Application.LoadLevel("MainMenu");
     }
     ////////////////////////////////////////////
 }

Now look at the pictures: alt text

capture1.png (222.5 kB)
Comment
Add comment · Show 7
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 Denvery · Oct 09, 2015 at 04:44 PM 0
Share

Please insert Debug.Log(...) into your Awake() and check if audio == null in Awake?

avatar image RandomCharacters Denvery · Oct 09, 2015 at 04:56 PM 0
Share

1) if I run it from the editor in the actual scene, it works fine. If I start at the main menu and have it load the scene, it doesn't work. It gives the error.

2) here is console with

Debug.Log(audio);

Input-Escape-$$anonymous$$ain$$anonymous$$enu (UnityEngine.AudioSource) UnityEngine.Debug:Log(Object) InputEscape:Awake() (at Assets/Extras Created/InputEscape.cs:25) ==========

3)After putting the debug line it has worked fine 20 times in a row. A Unity bug maybe?

avatar image Denvery RandomCharacters · Oct 09, 2015 at 05:30 PM 0
Share

It only gives the error after pressing the spacebar

$$anonymous$$ay be you've pressed Spacebar earlier then Awake() finished?

Show more comments
avatar image RandomCharacters · Oct 09, 2015 at 06:34 PM 0
Share

Now I'm getting this related error. this was fine and just starting doing this. Some unity bug?

$$anonymous$$issingComponentException: There is no 'Rigidbody' attached to the "Ball-Generated(Clone)" game object, but a script is trying to access it. You probably need to add a Rigidbody to the game object "Ball-Generated(Clone)". Or your script needs to check if the component is attached before using it. UnityEngine.Rigidbody.get_velocity () (at C:/buildslave/unity/build/artifacts/generated/common/modules/DynamicsBindings.gen.cs:784) Arrow.Update () (at Assets/$$anonymous$$iniGolf/Scripts-1/Arrow.cs:18)

Here is picture showing I have rigidbody. alt text

capture2.png (130.1 kB)
avatar image RandomCharacters RandomCharacters · Oct 09, 2015 at 06:37 PM 0
Share

and here is another picture of the game being played with the clone of the ball. There is a rigibody.

alt text

capture3.png (124.4 kB)
avatar image RandomCharacters RandomCharacters · Oct 09, 2015 at 06:55 PM 0
Share

I added this to with a debug.log.

    ///////////////////////////////////////////////////////////////
     void Awake()
     {
         Debug.Log("Rigidbody: " + GetComponent<Rigidbody>());
     }
     ///////////////////////////////////////////////////////////////

and look at picture. The debug says there is a rigidbody but then it says its missing. But its clearly there

alt text

capture4.png (30.1 kB)

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by engieelec · Oct 10, 2015 at 12:46 AM

Should it be

private AudioSource audio;

?

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 Gilles_aerts · Oct 09, 2015 at 06:18 PM

Hi try making a public or private audioSource variable instead of new audioScource

( private AudioSource audio ; )

Start(){ audio = getComponent(AudioSource) as AudioSource;

}

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 money4honey · Oct 12, 2016 at 03:53 PM

I was have this error too. In my case maybe it happened because I add some audio files to project folder through file system. I heard it may cause some bugs. But, then I re import all audios it solved the problem

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

33 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

Related Questions

Member cannot be accessed with an instance reference; qualify it with a type name instead 1 Answer

Getting this error every time i load my project (both 5.6.0f3 and 5.5.0f3, anyone can guide me to fix it? 0 Answers

Help with basic AI script 1 Answer

How can I baked Lighting with a large scene? 0 Answers

Couldn't find a key match for _gv.Inventory 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