utility create new prefab and createprefab from hierarchy doesn't seem to work in unity 5.6
Hello could somebody help please?
I want to create a prefab in c# code from a script like I use to be able to do, but doesn't seem to work the way the manual says it does.
UnityEditor.PrefabUtility.CreatePrefab(Application.dataPath + "/SavedPrefabs/" + prefabName + ".prefab", gameObject);
This does not work, nor does:
UnityEditor.PrefabUtility.CreateEmptyPrefab(Application.dataPath + "/SavedPrefabs/" + gameObject.name + ".prefab");
It only gives me an error cannot create prefab. Path is correct, name and extension is correct. Does it not work anymore since Unity 4.0? Please could someone solve this boggle? I've search google and unity answers and manual, and cannot find a solution as to why it doesn't work. Please help?
Answer by PizzaPie · Jun 05, 2017 at 01:04 PM
Actually its the path change it from :
Application.dataPath + "/SavedPrefabs/" + prefabName + ".prefab"
//to
"Assets/" + "SavedPrefabs/" + prefabName + ".prefab"
Cheers.
It works! Cool. So I had the path wrong. Thanks for your help!
Your answer
Follow this Question
Related Questions
Create a mesh with a scriptableObject directly from the editor. 0 Answers
How to add a component from a Custom Editor object field to a Prefab ? 1 Answer
Standard Assets unusable - Trying to use the ThirdPersonController Prefab 1 Answer
Comparing a gameObject's source prefab with a prefab 0 Answers
PrefabUtility.CreatePrefab() results in "not a valid asset file name" error? 2 Answers