Jump to content
This site uses cookies! Learn More

This site uses cookies!

armedunity.com uses cookies to improve user experience.

By continuing to use this site, you agree to allow us to store cookies on your computer.

  • 0
silasfriedrich

Object gets destroyed after reload the scene 2 times

Question

Hi everyone,

Im sorry if i ask to many questions but im a noob at unity :d . So I have this script:

Please login or register to see this code.

And its working perfect but now : this script is on a object in the scene 1 now i load scene 2 and its still there but now if I die in the scene 2 and press replay so it loads the scene again the object is gone. How can I fix that? Im thinking about a loop or something will work so i tried this:

Please login or register to see this code.

but i dont know what to write in the condition of the while.

Edited by silasfriedrich

Share this post


Link to post
Share on other sites

11 answers to this question

Recommended Posts

  • 0

You realise dontdestroyonload means that when you load a new scene objects arn't destroyed?

Share this post


Link to post
Share on other sites

  • 0

awake ans start are called once in the lifetime when instantiated, all the rest of the code does not make any sense. Just try this and delete rest of it

Please login or register to see this code.

Share this post


Link to post
Share on other sites
  • 0

It still does not work. The problem is that at the first time I switch the scene 1 to scene 2 it works, but if I reload the scene 2 the object is gone. And I want that the object is still there if I reload the scene 2.

Share this post


Link to post
Share on other sites
  • 0

Of course it doesn't, this will work only on the rest of the scenes. You should use awake and onlevelwaloaded.

Please login or register to see this code.

Share this post


Link to post
Share on other sites
  • 0

Are you destroying this object at anytime? It sounds like your destroying it or destroying its parent because dont destroy NEVER removes the object after its called unless you call to destroy it or its parent

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...