Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.