Hi,
I’m trying to create an Editor Utility to instantiate prefabs, but instead, it creates an object with a name like SomePrefab(Clone), and it loses the connection to the prefab.
This is the code simplified:
class AutoInstantiate extends EditorWindow {
var basePrefab : GameObject;
@MenuItem ("Window/AutoInstantiate")
static function Init () {
var window : AutoInstantiate = EditorWindow.GetWindow (AutoInstantiate);
window.Show ();
}
function OnGUI () {
basePrefab = EditorGUILayout.ObjectField("Base Prefab",basePrefab,typeof( GameObject) );
if (GUILayout.Button("Create Prefab"))
{
var newInstance = Instantiate(basePrefab);
}
}
}
What am I doing wrong? How can I get prefab instances instead of clones?
Thanks,
Thank you very much, that solved the problem.
In the documentation though, in the chapter “Instantiate prefabs at runtime”, it doesn’t say anything about that. Maybe EditorUtility.InstantiatePrefab should be included there.
Well, that part of the documentation is probably about things you can do in RUNTIME as the title suggest.
There’s a clear separation between the runtime clasees and the editor classes in the documentation for a reason. And I think it’s well justified.
If the Unity guys added references to editor classes inside runtime classes the documentation would be very confusing. And if so - why not reference runtime classes from within the editor classes documentation? Cross-reference everything.
It will create more confusion than good.
Even if you do need Editor scripts sometimes (And not all users do!) - It’s currently very easy to browse through Editor classes without being distracted with runtime classes you have no need for right now, and vice versa.