selecting prefab from project window with Editor script
Hi, struggling with this. I need to select a prefab from the project window as I want to populate my scene with prefabs when running an Editor script. Trying variations of this: prefab example is called 'eyes'
using UnityEngine;
using UnityEditor;
//#pragma warning disable
public class buildAssetsForFace : MonoBehaviour
{
[MenuItem("Examples/Instantiate Selected")]
static void cheese()
{
Selection.activeObject = AssetDatabase.LoadMainAssetAtPath("Assets/prefab/" + eyes + ".prefab");
}
}
from here
https://answers.unity.com/questions/37180/how-to-highlight-or-select-an-asset-in-project-win.html
But its super old and perhaps not relevant anymore
Answer by D-Coy · Oct 11, 2018 at 11:43 AM
For anyone else struggling with this
using UnityEngine;
using UnityEditor;
//#pragma warning disable
public class buildAssetsForFace : MonoBehaviour
{
[MenuItem("Examples/Instantiate Selected")]
static void populatePrefab()
{
GameObject Eyes = (GameObject)AssetDatabase.LoadAssetAtPath("Assets/prefab/eyes.prefab", typeof(GameObject));
GameObject clone = PrefabUtility.InstantiatePrefab(Eyes) as GameObject;
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612180120im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
[Custom Inspector] How to keep a reference to a selecion in a drop down menu? 0 Answers
Editor slider like "Quality Settings cascade split" 1 Answer
Editorscript: How to reference prefabs in editor not in awake or start 0 Answers
Spawning game objects in edit mode vanish after switching scenes 1 Answer
Editor tool for selecting inverse dependencies, no-longer works in Unity 5.4? 1 Answer