- Home /
EditorUtility on Android
I was using "EditorUtility.OpenFilePanel" to open an image in my game, and I wanted to see what the game might look like on mobile device, but as I built the game, it said there was compile error and the error was that "The name 'EditorUtility' does not exist in the current context". How come? It works fine on editor.
Everything within EditorUtility
is only available in the Editor - hence the name. That is, you cannot use it in builds, be it Android, iOS, Windows, Linux.
You need to implement IO operations yourself for this purpose - try to search for "opening files on Android".
Answer by swanne · Jul 16, 2018 at 02:17 PM
EditorUnity is intended for use only with Unity Editor. Building to any platform will require the UnityEditor code to be commented out or removed. If you wish to test your game on a phone and have the editor services, download the Unity Remote app. Its great!
I would only like to add that other options to exclude Editor-only code is to put them between conditional macros #if UNITY_EDITOR
- #endif
, or if the code can be put into a separate file, then use the new assembly definition files and mark it as Editor only (but I wouldn't recommend this, asmdefs are still pretty buggy).
Thanks. But if this API can only be used with Editor, why did they make this stuff? Nobody plays games on Unity. =_=
As the name says, it is utility for the editor - useful functionality that makes developing easier (especially if you are making editor extensions). However, for a game you probably want to make your own version (at the least to make it look different, so that your game stands out) of these things.
Answer by Voodoomedia · Apr 02, 2020 at 11:21 PM
Just include the code inside this notation:
#if (UNITY_EDITOR)
... your class/code ...
#endif
This is a great solution just to solve the error exception, but doesn't open the file explore.
Answer by niki1997 · Jul 17, 2019 at 05:33 PM
I have exactly the same problem. Did you find a solution on Android @a383338070 ?
Don't rely on code that has Editor
in its name in your game code. If you do, make sure to surround it with #if UNITY_EDITOR
and #endif
, so that it is not compiled into your game code. Editor functions like in EditorUtility
only work when inside the Unity Editor, when you build your game for any platform, they must be excluded with the above conditional compilation markers.
Your answer
Follow this Question
Related Questions
Missing Method Exception when trying to access EditorJsonUtility class methods 3 Answers
use of EditorUtility.CompileCSharp 1 Answer
How do I alphabetise the hierarchy after Scene Manager was implemented? 1 Answer
Inherited class not saving to List in PlayMode 1 Answer
How to open file csv in localdisk at runtime scene as data resources? 0 Answers