Search Unity

Missing Component Exception

Discussion in 'Immediate Mode GUI (IMGUI)' started by kilgore, Jun 12, 2009.

  1. kilgore

    kilgore

    Joined:
    Jan 6, 2009
    Posts:
    18
    Hello,

    I have run into an issue when trying to call a sound on a mouse click of a GUI button. I am getting "MissingComponentException" error from the line that calls the audio. I have attached the audio to the AudioClip variable multiple times and even have this audio call and audio clip working in another scene. I have also tried detaching and reattaching the script to my Camera and restarting Unity with no success. Posted below is the code I am using, the audio is being called in the loadIntro() function at the bottom. Thank you.





    Andrew

    Code (csharp):
    1.  
    2. var directionsTxt : Texture2D;
    3. var directionsWidth : int = 1024;
    4. var directionsHeight : int = 768;
    5.  
    6. var exitDownSound: AudioClip;
    7.  
    8. private var isLoading = false;
    9.  
    10. function OnGUI(){
    11.     if(gSkin){
    12.         GUI.skin = gSkin;
    13.     }else{
    14.         Debug.Log("startMenuGUI: GUI Skin object missing!");
    15.     }
    16.    
    17.     var backgroundStyle : GUIStyle = new GUIStyle();
    18.    
    19.     backgroundStyle.normal.background = backdrop;
    20.    
    21.     var directionsStyle : GUIStyle = new GUIStyle();
    22.     directionsStyle.normal.background = directionsTxt;
    23.    
    24.     GUI.Label(Rect(0, 0, Screen.width, Screen.height), "", backgroundStyle);
    25.     GUI.Box(Rect(Screen.width/2 - directionsWidth/2,Screen.height/2 - directionsHeight/2, directionsWidth, directionsHeight), "", directionsStyle);
    26.     GUI.Label(Rect(0, 20, 600, 100), "", "directionsMenuTitle");
    27.    
    28.    
    29.    
    30.     if(GUI.Button(Rect(Screen.width*0.5 - buttonWidths/2, Screen.height - 80, buttonWidths, 70), "exit")){
    31.         isLoading = true;
    32.         loadIntro();
    33.     }
    34.    
    35.     if(isLoading){
    36.         GUI.Label(Rect((Screen.width*0.5)-110, (Screen.height*0.5)-60, 400, 70), "Loading...", "directionsMenuTitle");
    37.     }
    38. }
    39. function loadIntro(){
    40.     audio.PlayOneShot(exitDownSound);
    41.     yield WaitForSeconds(2);
    42.     Application.LoadLevel("intro");
    43. }
    44.  
    45. @script ExecuteInEditMode()
    [/code]
     
  2. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    Forgive me if I'm missing something but the error is pretty darn clear. :) Add an audio source component, just like the error says to if you want to do things like call audio.PlayOneShot().

    Select the game object and then go to Component > Audio > Audio Source to add that component.
     
  3. kilgore

    kilgore

    Joined:
    Jan 6, 2009
    Posts:
    18
    Yeah of course I took a stab at adding an Audio Source to the camera as soon as posted this to the forum. Somehow I managed to look in every corner of the Forums/Reference/3D Tutorial without taking a gander at Audio Source. Sorry bout that, still very new at this.
    Andrew
     
  4. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    Next time read the error, love the error, respond to the error! :p

    Rock on and keep having fun!
     
  5. xxCoDzPrOzxx_5

    xxCoDzPrOzxx_5

    Joined:
    Apr 19, 2022
    Posts:
    1
    Hello there,

    I have run into an issue when trying to call an animator on a character for a game. I'm getting a "MissingComponentException" error from the line that calls the animation movement for my character. I attached an animator onto my selected character, but it says it is not attached, but a script is trying to access it. Posted below will be some screen shots of my code, along with the components I used. Thank you. Script Animator.PNG CharScript 1.PNG CharScript 2.PNG CharScript 3.PNG CharScript 4.PNG