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!
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
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:
Have a gameobject, with a script which does the following:
Gets a list of all the gameobjects in the scene, in a class member variable.
Disable all of them EXCEPT the gameobject itself.
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.
Do whatever you want to with the new scene. Afterwords…
Destroy the root object of the new scene.
Re-enable all of the objects in your saved list of gameobjects.
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.
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.