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 KnightRiderGuy · Feb 21, 2015 at 12:03 AM · timerdontdestroyonloadscene-changetimersuifont

UI Panel Don't Destroy On Load?

Is it possible say to have a timer on a slide out UI panel not destroy when a scene changes? For instance if I have a trip timer and I set the timer, then slide the panel with the timer on it out of view, then I go to another scene and then come back to that scene have the trip timer continue keeping accurate time? Hopefully I explained that right?

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 KnightRiderGuy · Feb 22, 2015 at 02:15 PM 0
Share

I'm still having trouble with this one, it seems I can get a regular GUI text timer to work on an empty game object. Now the odd thing is that if I make that game object a child of my canvas it is not visible in other scenes (Which is what I want) but if it is not a child of the canvas then it IS visible in other scenes (Which is what I don't want)

As for the other timer that is on my animated slide in panel and uses UI text, that one will ONLY play in my main scene regardless of how many variations of the Don't destroy on load I try. Can this even be done with the new UI system?

avatar image KnightRiderGuy · Feb 22, 2015 at 02:23 PM 0
Share

I hadn't noticed this before now bt when I exit my scene and then come back in that my timer game object is being duplicated?

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by DiegoSLTS · Mar 09, 2015 at 01:38 AM

You say you tried "a few variations" but it sounds you only tried setting the Panel to not be destroyed. I think the "DontDestroyOnLoad" only works with game objects at the top level of the hierarchy, if you set your Panel to not be destroyed but you let the Canvas containing it be destroyed, the Panel will be gone too.

Try calling the DontDestroyOnLoad for the Canvas or whatever is at the top level that contains the panel, every child of that object should still be there when you change the Scene.

Also, Neamtzu talked about making it a Singleton, but a singleton and something that is not destoyed when switching scenes are not the same thing. A singleton gameobject needs the DontDestroyOnLoad method, but you can keep anything from one scene to another even if they're not intended to be singletons.

Comment
Add comment · Show 4 · 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 KnightRiderGuy · Mar 09, 2015 at 02:38 AM 0
Share

I did try using the don't destroy on load on the canvas containing the panel. I made a new canvas, set it to top level and then put the don't destroy on that. $$anonymous$$y panel I then made a child of that canvas. It did carry my timer to other levels but when I return to the main level. Original level of the very fist timer it no longer functions.? This is very confusing and makes no sense to me as to why it would act that way.

I have also tried the same idea with my music player that has all sorts of elements attached to it like a music visualizer and text based spectrum data display and the same thing occurs with that when I return to it's origin level. the music still plays but not of the controlling buttons work any more and the music visualizer no longer works along with the text based spectrum data display. And yet all of these things are children of the canvas that has the don't destroy script on it???

avatar image DiegoSLTS · Mar 09, 2015 at 12:50 PM 0
Share

Remember that the only objects that will remain after the load level are the ones marked with DontDetroyOnLoad and their children, if your presistent object has references to other objects that are destroyed, those reference will be nulled, and if you return to that level the references will remain null, they're not automatically updated.

avatar image KnightRiderGuy · Mar 09, 2015 at 04:54 PM 0
Share

Yup, that's pretty much what is happening, now is there a way to fix that?

avatar image DiegoSLTS · Mar 10, 2015 at 12:45 PM 1
Share

I can think of a few methods:

  • $$anonymous$$ark every dependency to not be destroyed on level load too

  • Use the OnLevelWasLoaded method to search new objects in the loaded scene that can replace the destroyed ones

  • Similar to the second method, but ins$$anonymous$$d of the OnLevelWasLoaded put an object in the scene with a Start or Awake method that replaces the destroyed references.

But I've never done this, keeping objects between scenes works better to pass some data, when you have a lot of references it gets a lot harderd to make it right.

Also, consider maybe using LoadLevelAdditive to load the new level. Nothing will be destroyed, so you'll have to manually clean the scene, but it might be easier in some cases.

avatar image
0

Answer by Jabeebus · Jun 24, 2016 at 09:19 AM

To stop the panel from being destroyed, write this

 void Awake ()
 {
 DontDestroyOnLoad(this.gameObject);
 }

and attach it to the Canvas of the panel because UI's can only be visible if their in a Canvas parent.

The parent and the children won't be destroyed when you load something

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

22 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

Related Questions

Increase as timer decreases 1 Answer

What is a good method for tracking an array of different times? 2 Answers

Is it possible to make a timer that ignores timescale? 2 Answers

Will DontdestroyonLoad() Keep Child Objects too 2 Answers

Are there any performance differences between a timer and using Invoke? 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