Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
4
Question by ThisMayBeMadness · May 31, 2011 at 12:14 AM · editormonobehaviournamespacecs0246using

using UnityEditor outside of Editor folder when compiling build?

DESPERATELY need help. I have some scripts in a folder called Scripts, NOT in an Editor folder.

One of these scripts contains 'using UnityEditor'. It has a function it uses to save the state of the scene in a new scene, load another scene to play a video, then loads the temporary scene. This works fine in the Editor and everything is brilliant.

BUT when I go to compile the game in to a build, BAM, it doesn't work. I desperately need help and will be closely monitoring this question every minute until I have an answer or....something. I can submit code etc.

Main error:

"The type or namespace name `UnityEditor' could not be found. Are you missing a using directive or an assembly reference?"

I have read that to fix this error, the script in question should be moved to the Editor folder. This I do. Then other scripts fail because they don't know how to refer to the script in the Editor folder. Is there anything I can do? Please anyone, help! :(

Many thanks in advance.

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

4 Replies

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

Answer by sneftel · May 31, 2011 at 12:58 AM

Welll.... if you don't actually need to permanently save the game, just put it "somewhere" while some other scene is doing its thing, try this:

  1. Have a gameobject, with a script which does the following:

  2. Gets a list of all the gameobjects in the scene, in a class member variable.

  3. Disable all of them EXCEPT the gameobject itself.

  4. Load the new scene additively. This scene should have exactly ONE root object; all other objects should be its children. This root object should have a known name.

  5. Do whatever you want to with the new scene. Afterwords...

  6. Destroy the root object of the new scene.

  7. Re-enable all of the objects in your saved list of gameobjects.

Comment
Add comment · Show 6 · 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 ThisMayBeMadness · May 31, 2011 at 01:02 AM 0
Share

How do I load a scene additively? And make it work as you describe? I assume I go and use SetActiveRecursively(false) to disable the gameObjects etc.

avatar image sneftel · May 31, 2011 at 01:25 AM 1
Share

LoadLevelAdditive().

avatar image ThisMayBeMadness · May 31, 2011 at 02:54 AM 0
Share

$$anonymous$$any thanks, this set me on the right track and I've now managed to work around my issue and replace my save scene code, thank you very much. :)

avatar image fil · Dec 26, 2012 at 04:08 PM 0
Share

I have the same problem. I need to use the funcitons EditorUtility.OpenFilePanel, EditorUtility.DisplayDialog and EditorUtility.SaveFolderPanel and it's working great in editor mode, but when I try to build it, it give me the same error (The type or namespace name `UnityEditor' could not be found. Are you missing a using directive or an assembly reference? ). Help me please, don't know what to do :_(

avatar image Benproductions1 · Apr 16, 2013 at 05:37 AM 0
Share

@fil Ask a question as a question, not as a comment

Show more comments
avatar image
3

Answer by sneftel · May 31, 2011 at 12:24 AM

Damned if you do, damned if you don't. :-)

If the class is referenced (directly or indirectly) by code going into the build, but its functionality isn't actually used in the player, you can use conditional compilation to build a stub version into the player, which doesn't reference UnityEditor. Basically, like this:

 #if UNITY_EDITOR
 
 using UnityEditor;
 public class Whatever {
     public void foo() { EditorApplication.Beep(); }
 }
 
 #else
 
 public class Whatever {
     public void foo() { }
 }
 
 #endif
Comment
Add comment · Show 5 · 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 ThisMayBeMadness · May 31, 2011 at 12:33 AM 0
Share

This provides a new error.

"The type or namespace name `quests' could not be found. Are you missing a using directive or an assembly reference?"

quests is the script containing the 'using UnityEditor' stuff.

avatar image sneftel · May 31, 2011 at 12:42 AM 0
Share

$$anonymous$$ake sure that you have a stub version after the #else which compiles properly on its own.

avatar image ThisMayBeMadness · May 31, 2011 at 12:45 AM 0
Share

It can't, the save function is vital, basically it saves the scene in its current state in-game, then loads a different scene which plays a video, then jumps back. Is there any alternate way to save a scene in Unity in-game?

avatar image sneftel · May 31, 2011 at 12:50 AM 0
Share

Sure, but if it's going to be in the player, it can't be use UnityEditor functionality. There's stuff on the wiki about serializing game state.. take a look there.

avatar image ThisMayBeMadness · May 31, 2011 at 12:52 AM 0
Share

Serializing game state? I'll take a look now, but it's around 2am and time is running out. Any pointers,further advice etc would be $$anonymous$$UCH appreciated.

avatar image
0

Answer by Dune · Apr 16, 2013 at 04:48 AM

I tried a bunch of these solutions and ones very similar to this. Nothing was working until I realized I had a few empty .js files that I had saved and never added any script to. Once I deleted these blank .js files everything seemed to work. Double check any scripts you may have left blank and if you have any delete them.

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 N3 studios · Jul 02, 2013 at 04:16 AM 0
Share

omg haha you're amazing! id vote you up but i cant yet.. i had tried most solutions and nothing was working for me. i tried yours, realized i had one blank .js , deleted it, and now it works! thanks!

avatar image
0

Answer by Kevin Barnhill · Apr 25, 2013 at 10:25 PM

Just remove the "using UnityEditor;" and you're golden.

In batch mode, if you pull in UnityEditor, but are not referencing any of its objects, Unity preprocessor doesn't know to skip that library so it throws the error.

Comment
Add comment · 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

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

8 People are following this question.

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

Related Questions

UnityEngine found but MonoBehaviour or Vector3 not found in MonoDevelop 1 Answer

Is there a way to see namespaces in Editor ? (complete class name) 0 Answers

Monobehaviours & Editors with Inheritance across DLL boundaries don't load into Unity 2 Answers

Assign a MonoBehaviour script to a variable. 2 Answers

Unable to access custom editor namespace from runtime assembly 1 Answer


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