Skip to content

Instantly share code, notes, and snippets.

@Denchyaknow
Created March 27, 2023 08:57
Show Gist options
  • Save Denchyaknow/f070c728b61da26a533ead07ba7bff8a to your computer and use it in GitHub Desktop.
Save Denchyaknow/f070c728b61da26a533ead07ba7bff8a to your computer and use it in GitHub Desktop.
HowTo_CustomInspector_Prefabbing
//Creating a Prefab from Custom Inspector To create a Prefab from a custom inspector, you can use the PrefabUtility.CreatePrefab method. Here's an example of how you can use this method:
using UnityEditor;
using UnityEngine;
public class MyCustomEditor : EditorWindow
{
[MenuItem("MyTools/CreatePrefab")]
static void CreatePrefab()
{
// Get the selected object in the editor
GameObject selectedObject = Selection.activeGameObject;
// Create a new Prefab from the selected object
Object prefab = PrefabUtility.CreatePrefab("Assets/Prefabs/" + selectedObject.name + ".prefab", selectedObject);
// Select the new Prefab in the editor
Selection.activeObject = prefab;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment