Prompting dialogue box for input in Editor?

I’m trying to create a script for the Unity Editor that creates an empty prefab. I’m using c#.

How can I launch a dialogue or prompt box asking user to input the name of the prefab to be created?

You have two choices, you can create a custom editor window with a text field, or alternatively use the “Save As” window to save the prefab asset.

Using the “Save As” interface

The following example will display the standard OS provided file selector.

string path = EditorUtility.SaveFilePanelInProject("Save Your Prefab", "InitialName.prefab", "prefab", "Please select file name to save prefab to:");
if (!string.IsNullOrEmpty(path)) {
	// Actually save your prefab!

For further information refer to EditorUtility.SaveFilePanelInProject

Creating a custom editor window

Here is a simple example of how you might create a window to achieve this.

using UnityEngine;
using UnityEditor;

class SavePrefabWindow : EditorWindow {

	string prefabName;

	void OnGUI() {
		prefabName = EditorGUILayout.TextField("Prefab Name", prefabName);

		if (GUILayout.Button("Save Prefab")) {

	void OnClickSavePrefab() {
		prefabName = prefabName.Trim();
		if (string.IsNullOrEmpty(prefabName)) {
			EditorUtility.DisplayDialog("Unable to save prefab", "Please specify a valid prefab name.", "Close");
		// You may also want to check for illegal characters :)
		// Save your prefab