- Home /
How to call Screen.SetResolution() only once before the first scene starts loading ?
Hi,
I am trying to set the screen resolution for mobiles before the game starts loading the first scene. I tried puting the Screen.SetResolution() on Awake() method of the singleton gameobject that i use on every scene that loads asynchronously, but there seems to be a problem when i open the game on android phones because of the transition of the screen change that happens during the call of Screen.SetResolution(). The transition only happens for less than 200 ms but users can see that and looks like a bug and it is not that beautiful. Also, when the game opens, the first scene that loads is a scene that has the script to load every other scene that is selected during the game by the user and is loaded asynchronously showing a progress bar. I tried using a coroutine with "yield return new WaitForEndOfFrame()" in order to hide the transition from being displayed and delay the loading of the first scene and it works fine but the codes I am using for this are not on the persistent gameobject script. They are in the first scene which gets destroyed everytime after the selected scene is loaded. I stored a bool variable and set it to false on the persitent scene and called that when the Screen.SetResolution() coroutine was executed in order to prevent the resolution being set everytime a new scene is selected by the user. All works fine but i just wanted to know if there is a better way to make all of this inside the persistent gameobject script or the singleton i am using to control my game.
Here you have the code delays scene loading until the Screen.SetResolution() is finished :
void Start()
{
if (!GameControl.control.screenResolutionIsSet) {
StartCoroutine ("LoadWhenScreenResolutionIsSet");
} else {
//If Screen.SetResolution() was executed once there is no need to repeat that...
LoadNextScene ();
}
}
private IEnumerator LoadWhenScreenResolutionIsSet()
{
Screen.SetResolution(720, 1280, true);
yield return new WaitForEndOfFrame ();
yield return new WaitForEndOfFrame ();
yield return new WaitForEndOfFrame ();
LoadNextScene ();
GameControl.control.screenResolutionIsSet = true;
}
public void LoadNextScene()
{
//Here I load selected scenes asynchronously....
}
If anyone has an idea please share it. Thank you, Gerald.
Answer by JonPQ · Jan 16, 2018 at 12:02 AM
Make a setup scene... have that be the first scene, then make that scene load the next scene
hiding the glitch... fade screen to black or other plain color before switching... crap solution, but works.
Your answer
Follow this Question
Related Questions
how I can change the screen resolution in real time? 1 Answer
How to make game recognise Screen resolution on startup 1 Answer
How to Change Screen Resolution in game 2 Answers
Can I customize the resolution window that appears at the start of my executable? 2 Answers
Changing screen resolution is cutting the very edge of my screen off 1 Answer