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
0
Question by a383338070 · Jul 16, 2018 at 02:13 PM · editorutility

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.

Comment
Add comment · Show 1
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 Harinezumi · Jul 16, 2018 at 02:17 PM 1
Share

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

3 Replies

· Add your reply
  • Sort: 
avatar image
1

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!

Comment
Add comment · Show 3 · 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 Harinezumi · Jul 16, 2018 at 02:33 PM 0
Share

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

avatar image a383338070 · Jul 16, 2018 at 02:53 PM 0
Share

Thanks. But if this API can only be used with Editor, why did they make this stuff? Nobody plays games on Unity. =_=

avatar image Harinezumi a383338070 · Jul 16, 2018 at 03:04 PM 1
Share

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.

avatar image
1

Answer by Voodoomedia · Apr 02, 2020 at 11:21 PM

Just include the code inside this notation:

 #if (UNITY_EDITOR) 
 ... your class/code ...
 #endif
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 sekmani52 · Jan 18 at 07:20 PM 0
Share

This is a great solution just to solve the error exception, but doesn't open the file explore.

avatar image
0

Answer by niki1997 · Jul 17, 2019 at 05:33 PM

I have exactly the same problem. Did you find a solution on Android @a383338070 ?

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 Harinezumi · May 01, 2020 at 02:22 PM 0
Share

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

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

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

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


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