2
\$\begingroup\$

I'm working on a script to battle against nested prefabs. The script finds and replaces certain prefabs with a new version of that prefab. Now finding the prefabs is easy:

prefabList.AddRange(GameObject.FindObjectsOfType(typeof(GameObject)).Where(x => x.name == "PrefabName"));

But how can you instantiate a prefab in an editor script when the prefab is not in a resources folder? From what I read the PrefabUtility.InstantiatePrefab is used to do that, but I need a reference to the object which is instantiated.

\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

You have a number of options. For example, you can load a prefab by name, use the selected object(s) in the editor, or assign a prefab to a property through an Editor Window.

AssetDatabase.LoadAssetAtPath
Selection
Showing a property in an editor window

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .