Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
2
Question by crazymonkay · Jan 21, 2016 at 08:33 PM · runtimedisplayresolutionsmonitors

Possible to change display at runtime?

Hey,

So I've been implementing my own custom graphics options that can be altered at runtime. While most of these options are easily changed, one I can't figure out how to do is change the display (for fullscreen purposes).

Basically I need to do what the launcher does: Be able to select which display to use and have the list of available resolutions update to match whatever display you have chosen, all while the game is running. I found Display.displays, which gives you access to all connected displays, but I don't know how to actually change which display the game pulls the supported resolutions from and uses for fullscreen.

Thanks!

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

1 Reply

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

Answer by crazymonkay · Mar 05, 2016 at 07:02 PM

Welp after all this time the answer was very simple:

 PlayerPrefs.SetInt("UnitySelectMonitor", index); // Select monitor at index

This will automatically update the display the game is on and will update the Screen.resolutions array. You can use the Display.displays array to keep index within the appropriate bounds.

Edit: It seems that it is actually somewhat inconsistent as to whether or not it will change the game to the correct display, especially when changing Screen.fullscreen at the same time.

Edit 2: So changing the display the way mentioned above is very finicky. It also seems that the build will actually fullscreen to whichever display it is currently on, and the Screen.resolutions will actually update to match that display.

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 chasepettit · Oct 17, 2016 at 11:41 PM 8
Share

It took me a lot of testing to get this to work, but eventually I did find a bit of a nonsensical hack that allows me to consistently move the game to another display at runtime.

While I was running fullscreen at max resolution, the game would never switch to another monitor. However, if I changed the game resolution to anything lower than the native resolution, it would work every single time.

 private IEnumerator TargetDisplayHack(int targetDisplay)
 {
     // Get the current screen resolution.
     int screenWidth = Screen.width;
     int screenHeight = Screen.height;
 
     // Set the target display and a low resolution.
     PlayerPrefs.SetInt("UnitySelect$$anonymous$$onitor", targetDisplay);
     Screen.SetResolution(800, 600, Screen.fullScreen);

     // Wait a frame.
     yield return null;
 
     // Restore resolution.
     Screen.SetResolution(screenWidth, screenHeight, Screen.fullScreen);
 }

I can't explain why it works, but I hope someone might be able to find this helpful if they're pulling their hair out trying to figure this out.

avatar image GlitchCrew chasepettit · May 16, 2018 at 04:16 AM 0
Share

Hey, did you find the solution for a game not properly switching to another screen in the windowed mode and with the max possbile resolution? I have the same problem and I have no idea have to solve it.

avatar image chasepettit GlitchCrew · May 17, 2018 at 12:37 AM 0
Share

Sorry. I don't have any improvement to what I have there. It's not great, but it works so I'm fine with it.

avatar image pythongeko chasepettit · Jul 29, 2021 at 10:33 PM 0
Share

Thanks so much probably saved me 100s of hours.

avatar image FarSeer · Jun 29, 2017 at 02:31 PM 0
Share

Thanks for the solution, it helped greatly. I was trying to do some similar configuration via Command-Line Interface arguments at game launch, and nothing worked before that. Concerning application launch time, the trick works when called from the "Start" method in the Unity lifecycle, but not with "Awake". It seems the game engine always loads the monitor/resolution from the previous execution in between, and your Coroutine helps, especially with the "Wait a frame" part. Hope it helps too !

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

37 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 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

How to change the display at runtime. 1 Answer

Is it possible to switch monitor on a Mac? 0 Answers

UGUI Scaling across multiple monitors 0 Answers

Mutli Display doesnt update? 0 Answers

My multi-monitor support is broken. How can I fix this? 2 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