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
1
Question by Eroteme · Jan 27, 2014 at 04:41 PM · c#resolution

How to wait for Screen.SetResolution to finish?

Because of technical concerns, I need to run my Unity application in a "fullscreen" borderless windowed mode. The Unity window position and size is red from an external configuration file on start.

 ...
 Screen.fullScreen = false;
 Application.runInBackground = true;
 Screen.SetResolution (windowWidth, windowHeight, false);
 // ** Need to wait for the resolution to be changed here **
 SetPosition(windowX, windowY);
 ...


As you may be aware of, the Screen.SetResolution function takes a few seconds to get its job done. It runs on another thread. The problem with this code is that the window position can't be changed while the resolution is changing. Is there a way to 'block' the function until the resolution has changed?

I was thinking of a line like:

 WaitUntil (Screen.GetResolution() == wantedResolution)

Note: The SetPosition() function here calls SetWindowPos from user32.dll

Edit: This is written in C#!

Comment
Add comment
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

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Eroteme · Jan 27, 2014 at 05:51 PM

I found a quick fix for this issue.

I set my default settings in (File > Build Settings > Player Settings) which makes the code runs faster.

Then, I changed the code for:

 Screen.SetResolution (windowWidth, windowHeight, false);
 yield return new WaitForSeconds(0.5F);
 SetPosition(windowX, windowY);

This works properly; however a cleaner solution would be appreciated.

Comment
Add comment · Show 1 · 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 Barrett-Fox · Apr 09, 2014 at 08:57 PM 0
Share

Yes, this approach works. But I'd like a cleaner solution as well. Lot's of variety in the amount of time it takes a monitor to change resolution. I tried WaitForEndOfFrame(), but that didn't work.

avatar image
0

Answer by Kiloblargh · Jan 27, 2014 at 04:42 PM

 yield Screen.SetResolution (windowWidth, windowHeight, false);
Comment
Add comment · Show 1 · 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 Eroteme · Jan 27, 2014 at 05:02 PM 0
Share

I assume this is Javascript code; any way to get this to work in C#?

avatar image
0

Answer by ThomasKang · Oct 25, 2019 at 07:13 PM

Here's a cleaner fix than waiting for 0.5f seconds.

You can use a coroutine with WaitUntil()

Like so:

 void ApplyResolution(Resolution resolution) {
     Screen.SetResolution(resolution.width, resolution.height, Screen.fullScreen, targetFPS);
     StartCoroutine(_CalculateScreenResolution(resolution));
 }

 IEnumerator _CalculateScreenResolution(Resolution targetResolution) {
     yield return new WaitUntil(() => Screen.width == targetResolution.width 
         && Screen.height == targetResolution.height);
     scalableCamera.CalculatePixelRes();
 }
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

20 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

How to set an objects position to the corner of the screen? (Unity 2D) 2 Answers

Developing on multiple resolutions 1 Answer

GUI position and size in different screen resolutions 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