Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 PhilTuffler · Mar 31, 2015 at 11:30 AM · screencommand-linewindowedcommand linewindow-mode

Choose screen with Command line arguments

I am planning to run two or more instances of a "game" at a single PC and I need to start this automatically using command line scripts.

I start in windowed border-less mode using a FullHD resolution. According to http://docs.unity3d.com/Manual/CommandLineArguments.html this command should work, but it shows up at my first monitor no matter what. Maybe this just works in fullscreen?

 game.exe -popupwindow -screen-width 1920 -screen-height 1080 -adapter 2

Is there any other way to force the "game" to show on other monitors in windowed mode?

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

2 Replies

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

Answer by PhilTuffler · Apr 09, 2015 at 04:13 AM

The -adapter switch does not work in windowed mode. I have made a workaround using user32.dll to position the window at a deifined position

 game.exe -popupwindow -screen-width 1920 -screen-height 1080 -screen-position-x 1920 -screen-position-y 0

the C# code needed is:

 using UnityEngine;
 using System;
 using System.Collections;
 using System.Runtime.InteropServices;
 
 private static string[] startupArgs;
 
 public class PlaceWindow : MonoBehaviour 
 {
   #if UNITY_STANDALONE_WIN || UNITY_EDITOR
   [DllImport("user32.dll", EntryPoint = "SetWindowPos")]
   private static extern bool SetWindowPos(IntPtr hwnd, int hWndInsertAfter, int x, int Y, int cx, int cy, int wFlags);
   [DllImport("user32.dll")]
   static extern IntPtr GetForegroundWindow();
   
   public static void SetPosition(int x, int y, int resX = 0, int resY = 0) 
   {
     IntPtr hWnd = GetForegroundWindow();
     SetWindowPos(hWnd, 0, x, y, resX, resY, resX * resY == 0 ? 1 : 0);
   }
   #endif
 
   public static string getStartupParameter(String parameter)
   {
     if(startupArgs == null)
       startupArgs = Environment.GetCommandLineArgs();
     string s = null;
     for(int i = 0; i < startupArgs.Length; i++)
     {
       if(startupArgs[i].Equals(parameter) && startupArgs.Length >= i+2)
         s = startupArgs[i+1];
     }
     return s;
   }
     
   // Use this for initialization
   void Awake () 
   {
     int x = int.Parse(getStartupParameter("-screen-position-x"));
     int y = int.Parse(getStartupParameter("-screen-position-y"));
     SetPosition(x,y);
   }
 }
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 Brockoala · Dec 29, 2021 at 12:25 PM 0
Share

Omg thank you!!

avatar image
0

Answer by pachermann · Feb 27, 2020 at 01:08 PM

This is amazing, thank you so much for this solution!

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Simultaneous Unity & Command Prompt? 0 Answers

[Help] FullScreenMode - what is it? 0 Answers

Class could not be found when executing method from command line (-executeMethod) 0 Answers

sign apk from jenkins/commandline,how to sign android apk through jenkins/command line 0 Answers

Lock mouse to application. 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