- Home /
Custom Unity Editor Issue
I have this code:
using UnityEngine;
using UnityEditor;
using System.Diagnostics;
public class UnityEditorClass {
[MenuItem("Tools/Build Project")]
public static void BuildGame()
{
//get the path
var path = EditorUtility.SaveFolderPanel("Save Project", "C:/Projects/MyClasses/", "Test");
//get level name
string[] levels = { "C:/Projects/MyClasses/GSP290/MyFirstGame/Assets/Scene/MyTestScene.unity" };
// Build player
BuildPipeline.BuildPlayer(levels, path + "/Test.exe", BuildTarget.StandaloneWindows, BuildOptions.None);
// Copy a file from the project folder to the build folder, alongside the built game.
FileUtil.ReplaceFile("C:/Projects/MyClasses/GSP290/MyFirstGame/Assets/vector2.dll", path + "/" + "vector2.dll");
FileUtil.ReplaceFile("C:/Projects/MyClasses/GSP290/MyFirstGame/Assets/matrixHelper.dll", path + "/" + "matrixHelper.dll");
// Run the game (Process class from System.Diagnostics).
Process proc = new Process();
proc.StartInfo.FileName = path + "Test.exe";
proc.Start();
}
}
It works fine except, that it doesn't recognize the file specified when it auto-runs. It gives me this error:
Win32Exception: The system cannot find the file specified.
If anyone has come across this problem and knows how to fix it please share and thanks in advance!
Answer by numberkruncher · Jan 15, 2014 at 07:44 PM
This exception corresponds to your usage of Process
rather then the Unity editor API. You may find the following Q&A from StackOverflow helpful:
You may want to try adding Debug.Log(path + "Test.exe");
below line #20 in the snippet and then verify that this path does in fact exist.
@numberkruncher I saw that the name is right but the file name is TestTest.exe
I figured it out! In line 24 what I was missing was a forward slash inside the string that says "Test.exe" so in conclusion it is:
proc.StartInfo.FileName = path + "/Test.exe";
It is always a good idea to use Path.Combine(path, "Test.exe")
since that will handle the slashes for you. This is inside the System.IO
namespace.
Your answer
![](https://koobas.hobune.stream/wayback/20220613130533im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Equivalent of OpenFilePanel without using UnityEditor? 5 Answers
Working with Unity Editor 1 Answer
Custom Editor for interfaces 2 Answers
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer