Dawnkeeper Dawnkeeper - 1 year ago 121
C# Question

Pass argument to running Unity game

Is there a way to pass a parameter to a running game by starting it again?

For a 'normal' application I could do something like this.

Does Unity have a feature to allow notification of another instance being started with parameters?

Answer Source

No "built-in solution" for that. What you can do is:
a) Set up your game so it can run in one instance only (Edit -> Project Settings -> Player)

Forced Single Instance in Unity 5

b) As soon as you start, read a Player Setting, let's say a bool called "Running". If true, check if your app really is running with GetProcessesByName (if it doesn't, your app hang up before). If it's "false", set it to "true" (and back to false when one quits the game)

As of "passing a value", that works with "b" option only obviously. I would also use Player Settings for that:
if game is already running, write a value (e.g. under an "inputparam" key) and quit. Otherwise run (i.e. keep running) and check this setting's value every now and then, every frame or once a minute, whenever, depending on how critical it is for you to get the input value.

Long story short, there are workarounds, but no "supported way" for this, as far as I can tell.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download