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 · Jan 23, 2015 at 04:42 PM · scene-switchingsave datasettingsscene-changesounds

Remember scene settings when returning to scene

I'm not sure what to call this function or game mechanic. But lets say i have a scene where UI buttons control things like animation and sound on a UI interface GUI and I press a pause animation and sound button but yet when I exit that scene and later come back to it my music and animation will be playing by default and NOT pause from my last visit. Hopefully I'm explaining this right.?

Is there a way in C# to remember such setting across scene changes? Perhaps with some kind of manager or something?

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 meat5000 ♦ · Jan 23, 2015 at 04:58 PM 0
Share

Could use playerprefs, if your scene is set up in a way which works with this.

You must appreciate what is involved when it comes to saving a scene, mid-progress. You pretty much need to record everything and reproduce it when required.

avatar image KnightRiderGuy · Dec 18, 2015 at 03:56 AM 0
Share

Inspector Children $$anonymous$$issing Inspector child object go missing when I return to main scene?

screen-shot-2015-12-17-at-90150-pm.png (44.0 kB)

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Fourthings · Jan 23, 2015 at 05:00 PM

Yep, PlayerPrefs

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 wesleywh · Jan 23, 2015 at 04:56 PM

So you will need a GameObject that won't be destroyed between scenes. So you can attach a script to that object that can store variables between scenes. You will need to attach a DontDestroyOnLoad code.

Here is Unitys API on it: http://docs.unity3d.com/ScriptReference/Object.DontDestroyOnLoad.html

In that objects script you can check it for some play or pause bool.

Comment
Add comment · Show 5 · 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 · Jan 23, 2015 at 06:45 PM 0
Share

Is there a good tutorial anywhere on how to implement all of this stuff?

avatar image Fourthings · Jan 23, 2015 at 07:11 PM 0
Share

It's very simple, whatever script you store all your settings/prefs on add the below code and it will now survive the transition from one scene to another. This means whatever variables that have changed on this script will stay changed until you quit the game.

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

If you want the data to survive even after you've quit the game so it persists the next time you play, you'll need to use PlayerPrefs that I linked above, and don't be daunted it's pretty easy to use too. For tutorials just search on youtube

Edit - Just note, the gameObject this script it on wil survive the transition, and all of it's components, including other scripts. So it might be best to create a gameobject specificaly for this script. And make sure it doesn't already exist in the scene you're going to to avoid duplicates

avatar image KnightRiderGuy · Jan 23, 2015 at 07:39 PM 0
Share

O$$anonymous$$ I tried doing sort of what you have here like this: using UnityEngine; using System.Collections;

 public class UI$$anonymous$$anagerScript : $$anonymous$$onoBehaviour {
 
     void Awake () 
     {
         DontDestroyOnLoad (transform.gameObject);
     }
 
 
     public Animator LEDlights;
 
 
     public void PlayLEDLightsAnimation()
     {
         LEDlights.SetBool("isPlaying", !LEDlights.GetBool("isPlaying") );
     }
 }

Now this is on an empty game object that the UI button calls to, but when I pause the animation and exit the scene and come back in my animation is playing so something is missing here?

avatar image Fourthings · Jan 24, 2015 at 10:28 AM 0
Share

The bool that tells the game whether or not it is paused needs to live on this UI$$anonymous$$anagerScript and any other script needs to be checking this bool on Start or Awake, or maybe even Update

avatar image KnightRiderGuy · Jan 24, 2015 at 01:10 PM 0
Share

Thanks Fourthings, yup this seems a little more complicated than I thought, I'll get my code guy to have a look at it when he gets back from his trip in a week, figured while he was away i would try and get some of the nit picky stuff done, did manage to get some stuff done so that saves him time there but this seems more something for him to look into, without a more detailed description of what goes where I'm kinda lost. Anyways thanks for the help it al least points us in the right direction and I know he will know exactly what you are talking about ;)

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

Change variable through multiple scenes 0 Answers

Re-loading a scene but on the background older scenes are displayed 1 Answer

Fadeout Issue 0 Answers

How to make Set Active true when scene loads 1 Answer

Get a float transferred between two scenes and scripts 3 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