Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 FogCZ · Oct 06, 2020 at 10:21 AM · error messageerror-messageaudiolistenerreloading

MissingReferenceException, please help :(

Okay so i spend hours trying to fix this and i still have no clue why is this error ocuring. I have button that when clicked plays ad and mute audio listener and then after ad is finished it automaticly enable audiolistener and some other stuff, this all works but when i restart my level using GetActiveSccene, the button works anymore as it plays the Ad but it wont mute the audiolistener instead gives me this error :

MissingReferenceException: The object of type 'AudioListener' has been destroyed but you are still trying to access it. Your script should either check if it is null or you should not destroy the object.

Unfortunately this block my other function connected to this. I have no idea how is this when im not either destroying audilistener object or disabling it, and when the scene is first played from editor it works perfectly fine so the error occurs somewhere when my lvl is reloading.

My AdManager script :

 public AudioListener listener;
 public SecondChance sc;

 private string playStoreID = "3840117";
 private string appStoreID = "3840117";

 private string rewardedAd = "rewardedVideo";

 public bool isTargetPlayStore;
 public bool isTestAd;

 private void Start()
 {
     Advertisement.AddListener(this);
     InitializeAdvertisement();
 }

 void Update()
 {
     listener = GameObject.Find("Main Camera").GetComponent<AudioListener>();
 }
 void InitializeAdvertisement()
 {
     if(isTargetPlayStore)
     {
         Advertisement.Initialize(playStoreID, isTestAd); return ;
     }
     Advertisement.Initialize(appStoreID, isTestAd);
 }
 public void PlayRewardedVideoAD()
 {
     if (!Advertisement.IsReady(rewardedAd)) { return; }
     Advertisement.Show(rewardedAd);
 }

 public void OnUnityAdsDidStart(string placementId)
 {
     listener.enabled = false;
 }

 public void OnUnityAdsDidFinish(string placementId, ShowResult showResult)
 {
     switch (showResult)
     {
         case ShowResult.Failed:
             Debug.LogWarning("Something went wrong with an Advertisement");
             break;
         case ShowResult.Skipped:
             break;
         case ShowResult.Finished:
             if(placementId == rewardedAd) 
             { 
                 Debug.Log("Reward The player");
                 listener.enabled = true;
                 sc.SCAnim();
             }
             if(placementId == interstitialAd) 
             {
                 Time.timeScale = 1;
                 Debug.Log("Finished interstitial"); 
             }
             break;
     }
 }

And my Script from which i controll buttons:

 public Rigidbody rb;
 public Text WatchAD;
 public Text Needxchance;
 public Animator anim;
 public Animator animScore;
 public AudioSource windFx;

 public InfinitePlayerMovement plmvmt;
 public InfinitePlayerCollision plc;
 public InfiniteLevelScore inflsc;

 public Button second;
 public Button restartBut;
 public Button menuBut;

 public float chances;
 public float playedAds;
 public float titletext;
 public bool elevated;

 private void Start()
 {
     second.enabled = false;
     restartBut.enabled = false;
     menuBut.enabled = false;
     playedAds = 0f;
 }
 private void Update()
 {
     //Title Text
     titletext = chances + 1;
     if (titletext > 2)
     {
         if (titletext == 3)
         {
             Needxchance.text = "Need a third chance ?";
         }
         else
         {
             Needxchance.text = "Need a " + titletext + "th chance ?";
         }
     }

     WatchAD.text = "Watch AD " + playedAds + "/" + chances;
     chances = plc.Crashes;
     elevated = plmvmt.cubeIsOnTheLeveledGround;
 }

 //Triggered by InfinitePlayerCollision
 public void SecondChanceScreen()
 {
     animScore.SetTrigger("TextFade");
     anim.SetTrigger("SecondChance");
     Time.timeScale = 0f;
     windFx.Stop();
     second.enabled = true;
     restartBut.enabled = true;
     menuBut.enabled = true;
     plmvmt.cubeIsOnTheGround = false;
 }
 public void AdPlayed()
 {
     playedAds += 1;
     Invoker.InvokeDelayed(SCAnim, 0f);
 }

 public void SCAnim()
 {
     plmvmt.OnlyOnce = false;
     playedAds += 1;
     if (playedAds == chances)
     {
         anim.SetTrigger("SecondChanceClose");
         Invoker.InvokeDelayed(SecondChanceOpen, 0.7f);
     }
 }
 public void SecondChanceOpen()
 {
       playedAds = 0;
       animScore.SetTrigger("TestClip");
       Debug.Log("2ndChance");

       //Physical changes to Player
       rb.velocity = new Vector3(0f, 0f, 50f);
       if (elevated == false)
       {
           rb.transform.position = new Vector3(0f, 20f, rb.transform.position.z);
       }
       if (elevated == true)
       {
           rb.transform.position = new Vector3(0f, 35f, rb.transform.position.z);
       }
       rb.transform.rotation = Quaternion.Euler(0, 0, 0);
       Time.timeScale = 1f;

       second.enabled = false;
       restartBut.enabled = false;
 }

 public void Restart()
 {
     Debug.Log("Restart");
     FindObjectOfType<InfiniteGameManager>().Restart();
     Time.timeScale = 1f;
     second.enabled = false;
     restartBut.enabled = false;
     menuBut.enabled = false;
 }

 public void Menu()
 {
     Debug.Log("Menu");
     second.enabled = false;
     restartBut.enabled = false;
     menuBut.enabled = false;
     inflsc.scoreIncreasing = false;
 }

I found out that when i removed the listener function, it started writing error on Animator in the second script and when i tried to move audilistener component or move the listener function, it still made this error but with just diffferent script linked to it. Please help im desperate and i wasted countless hours on this problem. :(((((

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by FogCZ · Oct 06, 2020 at 09:40 PM

Just setting variables static fixed the issue and moved it somewhere else, but its a step and im on way to fix the rest of issues.

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

138 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Error While Build APK Signed,Error while build APK Signed. 0 Answers

Issues when trying to build game 'Error building Player because scripts have compile errors in the editor'... 0 Answers

Weird Error after Update 4 Answers

Script Error 1 Answer

Migration from Unity 5.5.0f3 to Unity 2017- error and HoloLens app not building 0 Answers


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