Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

MissingReferenceException: The variable doesn't exist?

Discussion in 'Scripting' started by GamesOnAcid, Jan 15, 2016.

  1. GamesOnAcid

    GamesOnAcid

    Joined:
    Jan 11, 2016
    Posts:
    280
    Hi, I am calling a sound to be played with the variable being called as
    Code (JavaScript):
    1. var MySound : AudioSource;
    and calling it in the update function under
    Code (JavaScript):
    1. if(Effect.current >= 20)
    2. {
    3.      MySound.Play();
    4. }
    I am using multiple audio sources for 4 different sounds, and for some reason, it says the variable does not exist. Can anyone tell me why?
     
  2. Fluzing

    Fluzing

    Joined:
    Apr 5, 2013
    Posts:
    815
    This has been answered a million times and Google is your friend. Programming requires a lot of searching of sollutions to problems. If you look closely to what the error exactly says, you should also be able to figure it out.
     
  3. GamesOnAcid

    GamesOnAcid

    Joined:
    Jan 11, 2016
    Posts:
    280
    I obviously looked online before I came here, and none of the solutions worked for me, hence why I am here.
     
  4. eisenpony

    eisenpony

    Joined:
    May 8, 2015
    Posts:
    971
    From what you say, I see no reason Unity would tell you the variable does not exist.

    It's really hard to guess at syntax errors from code snippits. Put your whole script here, or create a new script with the smallest amount of code to reproduce the problem and show us that. Also include the entire error message, preferably copy pasted, sometimes there are bits which don't seem important but can help other's remember how they solved a similar problem. We will try our best to help.
     
    Nigey likes this.