4
\$\begingroup\$

I created a very simple console application:

namespace ConsoleApplication4
{
    class Program
    {
        static void Main(string[] args)
        {
            // The project I want to open
            var arg = @"""-projectPath C:\Users\Administrator\Downloads\New Unity Project""";

            // Start Unity and open the project
            Process.Start(@"C:\Program Files\Unity\Editor\Unity.exe", arg);
        }
    }
}

But only the Unity Editor is launched; the specified project is not opened.

What do I need to modify to launch the project?

\$\endgroup\$
3
  • \$\begingroup\$ I've tried with and without the extra quotation marks but nothing happened. \$\endgroup\$ Commented Dec 18, 2016 at 6:47
  • \$\begingroup\$ Since the path to the project contains spaces, I would surround it with quotes. \$\endgroup\$ Commented Dec 18, 2016 at 13:27
  • \$\begingroup\$ did you mean to write @"\"-projectPath C:\Users\Administrator\Downloads\New Unity Project\"" ? \$\endgroup\$ Commented Dec 18, 2016 at 14:40

1 Answer 1

2
\$\begingroup\$

This might be a better question for the SuperUser StackExchange, as your problem isn't specific to game development, it's just about formatting your command line arguments correctly.

When you write arg like this:

var arg = @"""-projectPath C:\Users\Administrator\Downloads\New Unity Project""";

That's equivalent to typing this into your command line:

Unity.exe "-projectPath C:\Users\..." (etc)

As Hellium points out in the comments above, you want the quotation marks around the path, not the whole command line argument string. Like this:

var arg = @"-projectPath ""C:\Users\Administrator\Downloads\New Unity Project""";

Then in the command line it looks like this:

Unity.exe -projectPath "C:\Users\..." (etc)
\$\endgroup\$
1
  • \$\begingroup\$ Yes, I was thinking of posting on StackOverflow. Thank you for your help. This solved my problem. \$\endgroup\$ Commented Dec 18, 2016 at 22:06

You must log in to answer this question.