- Home /
Keeping prefab references when creating an object via editor script?
So I've gotten a basic editor script working to create modular ladders. Basically I click an up arrow in the scene and it will create a ladder segment by instantiating it from a prefab, modify the collider etc.
When I press the down arrow it will remove a segment etc, works fine.
My issue is that when I create a ladder segment - they come in as white objects, not linked to the original prefab. Guess I've never noticed this with instantiate before because I always use it at runtime. This is a problem if I need to change some value on the root ladder segment prefab. As an example i changed the texture, then added 2 more segments - nothing else updated. I changed it back and added some more, same thing.
How can I get these guys to come in "Blue"?

Answer by Jesse_Pixelsmith · Feb 01, 2014 at 09:57 PM
Sigh.. herp derp. I swear I searched for this, but only found this thread after posting... http://answers.unity3d.com/questions/21731/editor-script-instantiating-prefab-and-maintaining.html
Answer by DaveA · Feb 01, 2014 at 09:58 PM
You should look at http://docs.unity3d.com/Documentation/ScriptReference/PrefabUtility.InstantiateAttachedAsset.html and http://docs.unity3d.com/Documentation/ScriptReference/PrefabUtility.InstantiatePrefab.html
Your answer