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
10
Question by Brian 4 · Jun 11, 2010 at 09:25 AM · editor

Is there a define for "code is running in the editor"?

Is there some way for C# code to detect when it is running in the editor? For example, I want some debugging buttons to exist when running in the editor, but not when I build a web player version.

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

3 Replies

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

Answer by Mike 3 · Jun 11, 2010 at 09:29 AM

There isn't a define, but there is a property you can check for

if (Application.isEditor)
{
    //do stuff
}

http://unity3d.com/support/documentation/ScriptReference/Application-isEditor.html

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
avatar image
10
Best Answer

Answer by Molix · Jun 11, 2010 at 01:40 PM

Another one you can use for debugging is Debug.isDebugBuild. That is always true in the editor, but you can also see it in the runtime if you build with the "Development Build" option.

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
avatar image
15

Answer by yoyo · Mar 05, 2011 at 01:45 AM

As of Unity 3 there is now a UNITY_EDITOR define you can use.

If you have code that you only want in the editor, you can now do things like (C#) ...

void OnGUI()
{
#if UNITY_EDITOR
    if (GUILayout.Button("Edit"))
    {
        DoSpecialEditorStuff();
    }
#endif
}

You can apply this to methods, variables, even whole classes. Just be careful not to use something defined inside the #if block from a location outside such a block or you will have compilation problems on platforms where the code is compiled out.

Check out MSDN for more info on the C# preprocessor.

For more details on Unity's preprocessor defines, see the docs. There are also defines for the Unity version.

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

No one has followed this question yet.

Related Questions

Do scripts in a folder called "Editor" get left out of a build? 1 Answer

Reference a script from Editor folder 2 Answers

Compressing in OnPostprocessTexture yields "Not yet compressed" 1 Answer

Compiling Scripts Popup Appears Every Time You Switch to Unity 0 Answers

DrawGizmo attribute: GizmoType arg with incompatible flag values 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