Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 biebuster · Mar 05, 2016 at 10:42 AM · gameobjectparentscene-loading

Objects are destroyed/disfunctional after changing scene

http://imgur.com/XrrC7FR Bassicly whenever the pinball goes down to low, it hits a trigger (the deadzone) that resets the position of the ball, and respawns all the coins. Now all the coins are childs of a parent called CoinParent that has a script that handles detecting the amount of coins gotten, and also handling respawning all the coins. Now this all works totally fine IF i havent changed scene. BUT whenever i change scene, any refference in the CoinsParent script (CountCoins) to: transform, or gameObject will give me the following error:

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

Now it get's weirder. Because even if the CoinParent GameObject is not active, when the ball hits the deadzone and all the coins are supposed to reset, it gives me the excact same error, and that error when i click on it, takes me to the same place that i was taken when the CoinParent Gameobject WAS active. It's like it litteraly doesn't care if it's active or not.

I really have no idea how to fix this. it says the countCoin script is destroyed but it's clearly executing. also - yes - of course i have checked if either the gameObject or the transform are null in the script but that ALSO gives me the error, cause the script simply can't handle any refference to one of those two

Comment
Add comment · Show 6
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 shriya · Mar 05, 2016 at 02:22 PM 0
Share

please check if your script is attached to any other object by mistake

avatar image biebuster shriya · Mar 05, 2016 at 06:00 PM 0
Share

Any suggestions for practical ways of doing this that don't involve manually checking trough each and every object?

avatar image Glurth biebuster · Mar 05, 2016 at 06:08 PM 0
Share

To see which objects have your component attached, stick this in your awake or start function:

 Debug.Log("running code for object" + this.name);

this.name should show you the name of the gameobject it is attached to.

avatar image Glurth · Mar 05, 2016 at 06:19 PM 0
Share

without seeing your code: I'm not sure I understand the issue, but here is some possibly relevant information: When you initially define the scene that you are changing TO, in the editor, does it include a CoinParent Object(I would think it should)? Assu$$anonymous$$g so, THIS (second scene object) is the CoinParent object you need to reference in your scripts after you change the scene. From the error, it looks like the CoinParent object in the first scene is destroyed, when the new scene is loaded, (and referencing a destroyed object is obviously NOT going to work).

avatar image NoseKills Glurth · Mar 06, 2016 at 10:55 AM 0
Share

Yup. This would be my guess too. $$anonymous$$aybe you have a script with DontDestroyOnLoad or a static variable that references coin counter in the first scene. After loading a new scene, that script is still trying to reference the coin counter in the first scene.

avatar image biebuster Glurth · Mar 29, 2016 at 11:46 AM 0
Share

thing is though, the problem doesn't seem to be other scripts trying to use the countCoins script. It's all done with events, no individuel objects are targeted

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by aWolfKing · Mar 06, 2016 at 11:35 AM

http://docs.unity3d.com/ScriptReference/Object.DontDestroyOnLoad.html Hope this helps, i never used it but it might solve your problem.

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

Answer by biebuster · Mar 09, 2016 at 10:05 AM

Sadly this seems to make the problem even worse... Either the object is spawned once every frame, or it's not destroyed or spawned but EVERYTHING else than the object is destroyed. Really weird stuff

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

Answer by younes2234 · Apr 27, 2020 at 12:11 PM

Hi, this is generaly due to a wrong way of initializing variables ... just make sure that all your gameobject variables or any other local variables are intialized inside Start or awake , your problem doesn't require using dontdestroyonload .

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

47 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

Related Questions

Pausing an animation in a parent game object? 4 Answers

Make rotation gameobjects equal to parent 1 Answer

C# Check if parent's script's GameObject variable equals GameObject 2 Answers

Best practice for storing objects 1 Answer

change pivot of parent game object 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