- Home /
How to create and save Prefabs on device.
I am creating a gameobject and changings its property while playing. For example I have a doll and I am changing her skin tone , hair style , eye color on playing and then I am saving it.
I want my gameobject to be saved. Whenever I quit my application and restart it , gameobject shouldnt lose its property.
I was saving the prefab, created on run time. It runs on editor, but not on device. Please help.
Following is the code I am using to save. (works only on Editor)
Code
public void SavePrefab () {
GameObject doll = this.gameObject ;
doll.name = "Barbie";
prefab = EditorUtility.CreateEmptyPrefab("Assets/Resources/" + Barbie + ".prefab");
//prefab = AssetDatabase.CreateAsset("Assets/Resources/" + Barbie + ".prefab");
EditorUtility.ReplacePrefab(Barbie, prefab);
prefab.name = "Barbie" ;
AssetDatabase.Refresh();
}
Answer by Cherno · Jul 07, 2015 at 04:38 PM
Saving prefabs works only in the editor environment, that's true. You have to find workarounds to achieve what you want. For example, you can save the relevant data (name, mesh name, etc.) to a file in a way that is serializable.. or even as a .txt file.