Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Xymbiot3 · Jul 11, 2014 at 09:32 AM · scenenullreload

MissingReference When Reloading Scene

I am having an issue with variables throwing 'MissingReferenceException' errors after I reload the same scene I just finished playing. I've found other Answers similar to this one but none of those answers have fixed this issue so I'm thinking I might have a different root cause.

I am running a scene that has a 'Retry' button and when the user clicks it I call Application.LoadLevel("MyScene"). The first time my scripts access two specific objects I get the following:

 MissingReferenceException: The object of type 'TrollAudioManager' 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.

I've verified that all the components and objects including the TrollAudioManager is being cleared and calling Start() again like normal (which does the re-grabbing logic as well).

To prevent this error I've added a null check and re-grab the component if it's missing. However, if I then run a Play on that component (basically just a layer over a standard Audio Source), it plays two of the same clip with a single call to Play().

So the issue I'm struggling with:

1) If I don't put a null check and re-grab the components I get a MissingReference (which technically should already be set from Start)

2) If I put in that null check/ grab; the audio plays twice as if there were two components of that type playing (I've verified there is only one after the reload)

I've also made sure to check that all my objects aren't static and these objects aren't being sent to DontDestroyOnLoad anywhere.

I know it's hard to determine without the classes themselves, but any idea on a cause or solution?

Comment
Add comment · Show 2
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 rutter · Jul 11, 2014 at 09:08 AM 0
Share

At first glance, I'd assume that you have some reference being carried between scenes (maybe a static field?). If that's not it, something might be destroying the object in your scene.

According to the error message, the component did exist at one point... it's just been destroyed, since then.

avatar image Xymbiot3 · Jul 11, 2014 at 12:56 PM 0
Share

There is a static variable within that class however removing that doesn't fix the issue.

Actually even loading a different scene and then loading back into this one produces the same issue; so with my Hierarchy I can see the objects all get destroyed when the next scene loads and are recreated when the problem scene is loaded.

I do set some events within this code, could those references be seen as static?

1 Reply

· Add your reply
  • Sort: 
avatar image
4
Best Answer

Answer by Xymbiot3 · Jul 11, 2014 at 09:58 PM

I figured out the answer was due to setting events. I am using the 'Dialoguer' asset from the store and noticed the issue kept happening in the same event handler. After looking through the base code I found the function 'ClearAll()' which simply sets all the event handlers to null. Doing this before I re-set them releases those references to the old handlers and properly re-attaches the latest events.

I'm not great with event handlers but from what I gather they act almost like a pointer so simply trying to point them somewhere else without releasing what they point to currently was my issue.

Comment
Add comment · Show 1 · 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 bedorlan · Jan 09, 2016 at 09:38 PM 0
Share

yes, exactly that was happening to me. detaching the events from the handlers using -=, solved the problem.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

After scene reload script stopped working. 1 Answer

when i load scene, it starts same scene over 0 Answers

I have an error, script should check for null or not destroy game objects 2 Answers

Exceptions When Changing Scenes 2 Answers

GameManager and scene design issue. 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