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 Cobradabest · Apr 10, 2013 at 02:34 PM · c#graphicsresolutionloadingaspect-ratio

Is there a way to make a script do something every time a new level loads?

I have a bit of a problem, I've just recently added graphics options to my game, and it works fine, that is until I load a new level, then everything, with the exception of texture quality, resets.

I've made it so that the object that stores the graphic options data, doesn't get destroyed when a new level loads (DontDestroyOnLoad), but that doesn't seem to do much, I need to somehow make it so that when a new level is loaded, it sets all of the graphic options to the users preference, is there anyway I can do that?

I think I remember hearing about a void that does that, but I can't for the life of me remember what it was called, and I can't find the video where I heard about it.

Also, I'm wondering if it's possible to detect the aspect ratio of the players resolution, because I have loading screens set up for the game, and want to have widescreen load screens for widescreen resolutions and a normal ratio for the others.

Comment
Add comment · Show 3
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 ByteSheep · Apr 10, 2013 at 03:04 PM 0
Share

Why not just call some code in the Awake() function?
http://docs.unity3d.com/Documentation/ScriptReference/$$anonymous$$onoBehaviour.Awake.html
It gets called every time the script is initialized i.e. whenever a new scene is loaded.
You could create a script which sets the graphics to the user preferences in the Awake() function and then add the script to each scene you want to load the graphics options for.

avatar image Cobradabest · Apr 10, 2013 at 03:12 PM 0
Share

It doesn't seem to work, adding the apply function to the "Awake()" function doesn't seem to do anything.

avatar image Fattie · Apr 10, 2013 at 04:10 PM 0
Share

@merry -- he means (I assume) when you are using DONTDESTROYONLOAD

in that case Awake() DOES NOT run each time there's a level change. jarz has given dah answer.

1 Reply

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

Answer by janzdott · Apr 10, 2013 at 03:10 PM

Monobehaviour.OnLevelWasLoaded (int level) will fire when a certain level is loaded. If I were you, I would have the graphics object get destroyed when changing scenes, then just have one graphics object in every scene that you need it. Then whatever code you put in Awake () or Start () will get executed at the start of each scene. And Camera.aspect will return a float that is the aspect ratio (width/height)

Comment
Add comment · Show 2 · 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 Cobradabest · Apr 10, 2013 at 04:03 PM 0
Share

The problem with that is that the graphics object gets it's values from the menu objects in the menu, it doesn't reference them, but the objects themselves set the values through a static void, Do the object is first started it's blank. Which means the graphics won't apply to every new level, because the settings are back to default.

The solution you posted worked anyway, thank you!

avatar image janzdott · Apr 10, 2013 at 06:54 PM 0
Share

One thing you could do, to keep the settings between scenes, is use static variables for the fields you wish to keep. That's the easiest solution. Or you could use playerprefs or serialize them to a binary or xml file and load that file when changing scenes

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

12 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

Related Questions

ASPECT RATIO FILTER IN OnGUI? 3 Answers

Detecting and setting resolutions correctly 1 Answer

Handling Multiple Resolutions in 2D? 0 Answers

How do you save a player's prefered resolution in Unity 2017.1.1f? 0 Answers

Changing screen resolution is cutting the very edge of my screen off 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