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
7
Question by yatagarasu · Feb 26, 2014 at 05:48 PM · componentmonobehavioureditoronly

Is it possible to mark MonoBehaviour as EditorOnly

I have a MonoBehaviour which shows only debug stuff. Like object bounds. Don't want it to be available in final builds. Like GameObjects can be tagged as EditorOnly is there such possibility for MonoBehaviours?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Jamora · Feb 26, 2014 at 05:58 PM

You can put your class in an Editor folder. All classes in Editor folders (or any special folder, for that matter) go to a different assembly. The Editor assembly is not included in the build. See Unity Special Folders or the wiki page.

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 yatagarasu · Feb 27, 2014 at 08:50 AM 0
Share

$$anonymous$$onoBehaviours from Editor assembly are not visible in Add Component, that was what i found first and tried to figure out why this is happening. $$anonymous$$y debug monobehaviours became in editor folder after refactoring. So I tried to understand why, and this brings me to the question how should i manage editor only behaviours.

avatar image Jamora · Feb 27, 2014 at 11:23 AM 3
Share

You cannot use Editor $$anonymous$$onoBehaviours in the game build, if you try this the game will not compile. You cannot use $$anonymous$$onoBehaviuors from Editor folder from outside the Editor assembly.

If you find Editor scripts hard to use, or for some reason require functionality from these debugging scripts from within the game build, you can also use Platform dependant compliation.

Basically, You put your scripts in any assembly that is included in the build, then within those scripts deter$$anonymous$$e which lines of code should be included in the compilation.

Any code you don't want to include should look like the following:

 #if UNITY_EDITOR
 Debug.Log("This debug will not show up in the standalone.");
 int g = 5+1; //this variable won't be in the game build either
 #endif

avatar image vexe · Feb 27, 2014 at 11:29 AM 2
Share

That's what I do for my editors too.

 public class $$anonymous$$y$$anonymous$$B : $$anonymous$$B
 {
    // stuff...
    #if UNITY_EDITOR
    private bool debug;
    #endif
 }
 
 public class $$anonymous$$y$$anonymous$$BEditor : Editor
 {
     ....
     var sp_debug = serializedObject.FindProperty("debug");
     if (sp_debug.boolValue)
         // show debugging stuff
 }
avatar image
1

Answer by IgorAherne · Sep 03, 2018 at 09:10 PM

I just dedicate 1 gameObject to hold all such "debug scripts".

Then, use this to auto-mark gameObject as EditorOnly, including its scripts https://forum.unity.com/threads/editor-only-monobehaviour.508844/#post-3635764

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

23 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

Related Questions

Copying a Component's values without a new Game Object 1 Answer

Caching a Monobehaviour Component's reference properties (rigidbody2d, specifically) 1 Answer

Disabling GameObject doesn't disable components 0 Answers

Can you have multiple MonoBehaviors in the same script file? 1 Answer

Do you tend to have scripts to mark prefabs 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