create prefab via script (JS)


Ive tried many times, but i get errors and cant solve problem - create prefab from a gameObject.

Can someone help me out?

Here i add some gameObjects to a GameObject as children and after that i need to make a prefab out of that parent… I ve already tried

//add children snippet

//add prefab snippet
function MakePrefab() 
var prefab : Object = EditorUtility.CreateEmptyPrefab ("Assets/createdPrefab.prefab");
EditorUtility.ReplacePrefab(gameObject, prefab, ReplacePrefabOptions.ConnectToPrefab);

Thanks in advance! I guess it should also help other people, who are searching for solution to this problem.

At runtime (which you seem to be talking about), a prefab is just the same as any other inactive GameObject. If you’re talking about runtime, this is a no-op.

As to saving, you need to do that yourself at runtime. Search here for “save load” and you’ll get heap of advice on that part.