- Home /
Only able to save inside the editor problem
I just bought a package and it says it can save and it can but when I try to build it it comes up with a error about saving. How do I make it save some were else so that this doesn't happen. heres the error
here is the script
using UnityEngine;
using System.Collections;
using UnityEditor;
public class ModelEditorGUI : MonoBehaviour {
public enum GuiState{
Edit,
Save,
Load
}
public static GuiState currentGuiState = GuiState.Edit;
float sW = Screen.width;
float sH = Screen.height;
Rect colorRect = new Rect(Screen.width / 150, Screen.height / 100, Screen.width / 8, Screen.height / 8);
public static byte r, g, b;
public static Color32 currentColor;
public GUISkin skin;
public static int buildMode = 1;
public static int colorMode = 0;
public GUITexture crosshair;
string modelName = "";
//Icons
public Texture2D icon_colorPicker;
public Texture2D icon_colorChanger;
void Start () {
CustomMouseLook.canLook = true;
Screen.lockCursor = true;
ModelEditorPlayer.canBuild = true;
}
void Update () {
currentColor = new Color32(r,g,b,(byte)(colorMode == 0 ? 255 : 200));
if(Input.GetKey(KeyCode.LeftControl)){
CustomMouseLook.canLook = false;
Screen.lockCursor = false;
ModelEditorPlayer.canBuild = false;
}
else if (currentGuiState == GuiState.Edit){
CustomMouseLook.canLook = true;
Screen.lockCursor = true;
ModelEditorPlayer.canBuild = true;
}
}
void OnGUI () {
GUI.skin = skin;
//Color Area
if(currentGuiState == GuiState.Edit){
ModelEditorPlayer.canBuild = true;
crosshair.enabled = true;
GUI.Box(colorRect, "");
GUILayout.BeginArea(colorRect);
GUI.skin.label.alignment = TextAnchor.MiddleCenter;
GUILayout.Label("Color");
r = (byte)GUILayout.HorizontalSlider((int)r, 1, 255);
g = (byte)GUILayout.HorizontalSlider((int)g, 1, 255);
b = (byte)GUILayout.HorizontalSlider((int)b, 1, 255);
GUILayout.BeginHorizontal();
if(GUILayout.Button("Toggle Mode", GUILayout.Width(sW / 18))) buildMode = buildMode == 0 ? 1 : 0;
if(GUILayout.Button("Toggle Color", GUILayout.Width(sW / 18))) colorMode = colorMode == 0 ? 1 : 0;
GUILayout.EndHorizontal();
GUILayout.EndArea();
}
else if(currentGuiState == GuiState.Save){
ModelEditorPlayer.canBuild = false;
crosshair.enabled = false;
CustomMouseLook.canLook = false;
Screen.lockCursor = false;
GUI.Box(new Rect(Screen.width/2-Screen.width/10, Screen.height/2-Screen.height/12, Screen.width/5, Screen.height/6), "Save Map");
GUI.BeginGroup(new Rect(Screen.width/2-Screen.width/10, Screen.height/2-Screen.height/12, Screen.width/5, Screen.height/6));
GUI.Label(new Rect(10, 30, 100, 20), "Model Name:");
modelName = GUI.TextField(new Rect(80, 30, 130, 20), modelName);
if(GUI.Button(new Rect(10, 70, 200, 25), "Save Model as File")){
ModelSerializer.SaveModel(modelName);
currentGuiState = GuiState.Edit;
}
if(GUI.Button(new Rect(10, 95, 200, 25), "Save Model as Mesh")){
AssetDatabase.CreateAsset(ModelSerializer.ModelToMesh(), "Assets/Models/Mesh/" + modelName + ".asset");
currentGuiState = GuiState.Edit;
}
GUI.EndGroup();
}
if(currentGuiState == GuiState.Load) {
ModelEditorPlayer.canBuild = false;
crosshair.enabled = false;
CustomMouseLook.canLook = false;
Screen.lockCursor = false;
GUI.Box(new Rect(Screen.width/2-Screen.width/10, Screen.height/2-Screen.height/12, Screen.width/5, Screen.height/6), "Load Map");
GUI.BeginGroup(new Rect(Screen.width/2-Screen.width/10, Screen.height/2-Screen.height/12, Screen.width/5, Screen.height/6));
GUI.Label(new Rect(10, 30, 100, 20), "Model Name:");
modelName = GUI.TextField(new Rect(80, 30, 130, 20), modelName);
if(GUI.Button(new Rect(10, 70, 200, 25), "Load Model")){
StartCoroutine(ModelSerializer.LoadModel(modelName));
currentGuiState = GuiState.Edit;
}
GUI.EndGroup();
}
}
}
Answer by Bunny83 · Aug 13, 2014 at 12:27 AM
Oh that's easy. You simply can't. Who ever made this script only made it for in-editor use as he uses the AssetDatabase. I guess this should only be some sort of example. The actual model saving is done by the ModelSerializer. You can simply comment out the "Save Model as Mesh" button and the "using UnityEditor;" line at the top. That should make the class build-compatible.
If you have further problems with thrid party packages, please contact the creator of that package and don't ask questione here. You didn't even mention that you use "Voxity", that we had to read out of your screenshot...
Answer by Kiwasi · Aug 13, 2014 at 12:07 AM
UnityEditor is not included in built games. As the name implies its just for inside the editor.
Make the error go away by doing the following
#if UNITY_EDITOR
using UnityEditor;
#endif
You will need to do this around any part of the script that uses UnityEditor functionality.
that gives me a error and even if I fix that then I still need it to save some were else so that it can save
Your answer
Follow this Question
Related Questions
Loading data from a txt file - C# 3 Answers
Can't get serialization Load/Save to work!C# 3 Answers
Filestream/SaveManager 2 Answers
Save the inventory items to the database 0 Answers
Save and load serialization problem 0 Answers