Search Unity

Run unity on Linux from command line, with arguments

Discussion in 'Editor & General Support' started by pitou, Jul 21, 2014.

  1. pitou

    pitou

    Joined:
    Jul 15, 2014
    Posts:
    4
    Hi everyone, and sorry for my poor english.

    Ideally, I want to do the following things :
    1) building my game once for Linux
    2) executing it on Linux and giving it some arguments in command line, that I can fetch in a C# script

    The 1) is ok, my game works on Linux, but I don't find any way to do the second.


    I'm not sure there is a solution for what I need, but here an extended explanation :

    I have a "game" that I only use to generate video (I take a screenshot of every frame of my game during a defined time and generate a video from these screenshots).

    I want to execute my game in command line and add arguments (for example, the number of frame I want before quiting). There is a way to do it here http://epixcode.com/unity-custom-arguments-through-command-line/

    It works on windows (but you have to build the game every time, unless someone knows a way to avoid this?). The problem is, unity doesn't work really well on Linux, the installation is not stable depending the distribution, and in the documentation, they didn't even mention it's possible to use command line on Linux to run Unity. I didn't manage to install and run Unity correctly on my distribution.

    Is anyone has a clue of how I could run Unity in command line on Linux, and add arguments in it?

    The best for me would be to type in command line "./MyGame -arguments", and fetch these arguments in a script in my game.

    Ideally, I don't want to build my game each time, but if there is no other way I would build it every time.

    This is the documentation about unity in command.line :
    http://docs.unity3d.com/Manual/CommandLineArguments.html

    Thank you
     
    Last edited: Jul 21, 2014
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Why not use a config file instead?

    --Eric
     
  3. pitou

    pitou

    Joined:
    Jul 15, 2014
    Posts:
    4
    Please, tell me if I understand or if I'm wrong on the principle.
    1) I create an xml file with my arguments.
    2) I create a c# script MyArgumentScript that parse my arguments.
    3) I create an empty object, and add my script to this object.
    5) I make the variables of MyArgumentScript public.
    6) I add an object of MyArgumentScript in the other script I needed the arguments.
    7) When I execute my game, it will read the arguments in the file, and configure my whole game everywhere I use my arguments.

    A little question, how to be sure this config file is loaded and initialize before my other script? Because in the start function of other scripts, I need some specifics arguments.

    If this is all wrong, do you have a small example of how this could be done?
    To be honest, i have never used a config file before, I have very few notions of Unity, and all the example I find on config file and unity are really complicated for my poor knowledge.
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You can use standard script execution order techniques. i.e., use Awake for that and Start for other scripts, or use the script execution order settings in Unity, etc. Config files can be as simple or as complicated as you want to make them, since it's just reading a text file and doing something with the content.

    --Eric
     
  5. pitou

    pitou

    Joined:
    Jul 15, 2014
    Posts:
    4
    thank you, it works