Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by iamthecoolguy11 · Aug 12, 2014 at 11:54 PM · c#saveloadbuilding

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 alt text

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();
             
         }
 
     }
     
 
 }
 

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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...

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image iamthecoolguy11 · Aug 13, 2014 at 01:24 AM 0
Share

Thanks man :)

avatar image
0

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image iamthecoolguy11 · Aug 13, 2014 at 12:28 AM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

23 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges