Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Cannot get command arguments to work.

Discussion in 'Scripting' started by aCake0202, Jun 1, 2021.

  1. aCake0202

    aCake0202

    Joined:
    Mar 11, 2021
    Posts:
    26
    upload_2021-5-31_19-29-14.png

    Here's our code. Anything highlighted in orange can be ignored. Basically, after building the game and launching it with the line "-vrmode steamvr" doesn't do anything. Does anyone see what we're doing wrong here? Been working on this for days, getting frustrated.
     
  2. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,913
    It is because the space makes it into two separate entries:
    screenshot1.png

    Here's the code I'm running, just so you know how to do it:
    Code (CSharp):
    1. using System.Linq;
    2. using UnityEngine;
    3. using UnityEngine.UI;
    4. using static System.Environment;
    5.  
    6. public class TestCmd : MonoBehaviour
    7. {
    8.     [SerializeField]
    9.     private Text text;
    10.     private void Awake()
    11.     {
    12.         text.text = string.Empty;
    13.  
    14.         var args = GetCommandLineArgs();
    15.         foreach(var arg in args)
    16.         {
    17.             text.text += arg + "\n";
    18.         }
    19.  
    20.         text.text += args.Contains("-vrmode steamvr") ? "SteamVR\n" : "DunnoVR\n";
    21.         text.text += args.Contains("-vrmode=steamvr") ? "SteamVR==\n" : "DunnoVR==\n";
    22.     }
    23. }
    24.  
    I recommend using the -vrmode=steamvr parameter and simply look for it like that
    args.Contains("-vrmode=steamvr")
    .
    When I do
    Test2020LTS.exe -vrmode=steamvr

    screenshot2.png
     
  3. aCake0202

    aCake0202

    Joined:
    Mar 11, 2021
    Posts:
    26

    you are a life saver, thank you so much!!!
     
    Lurking-Ninja likes this.