- Home /
 
               Question by 
               siddharth3322 · Aug 16, 2019 at 02:12 PM · 
                audiosceneaudiosourcedontdestroyonloadmissingreferenceexception  
              
 
              MissingReferenceException in AudioSource on DontDestroyOnLoad GameObject
I was getting Missing Reference Exception within my Audio Source when I change my game scene and again move back to the same scene.
Before I change the main menu scene, it is working fine but after changing and moving back to the main menu scene, it is started showing this exception.

Here is the code I have written for AudioManager:
 public class AudioManager : MonoBehaviour
 {
     static AudioManager instance;
     //
     [SerializeField] AudioClip buttonClickClip;
     [SerializeField] AudioSource myAudioSource;
 
     private void Awake()
     {
         instance = this;
     }
 
     public static AudioManager Instance
     {
         get
         {
             return instance;
         }
     }
 
     public void PlayButtonClickSound()
     {
         if (GameManager.Instance.IsEnableSounds)
             myAudioSource.PlayOneShot(buttonClickClip);
     }
 
 }
Here is the code that I wrote for DontDestroyOnLoad purpose:
 public class DontDetroyOnLoad : MonoBehaviour
 {
     private static bool created = false;
 
     void Awake()
     {
         if (!created)
         {
             DontDestroyOnLoad(this.gameObject);
             created = true;
         }
         else
             Destroy(this.gameObject);
     }
 
 }
Now please give me some suggestion to solve this problem.
 
                 
                audio-source-error.png 
                (214.8 kB) 
               
 
              
               Comment
              
 
               
              Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                