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
0
Question by DamonD. · Jan 10, 2012 at 06:54 AM · erroreditorbuildeditor-scripting

How to exclude "Selection & Handles" and other editor-specific code in builds?

I am working on a custom editor script one of the options is to select the parent of the object

 Selection.activeGameObject = transform.root.gameObject;

I am also using Handles.Label to display a number to identify waypoint gizmos when I go to build the game i get unknown identifier selection and the same for handles with some research i found that these can not be built into the game

my question is can i make it ignore them when i build rather than remark them out thank you in advance.

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
0
Best Answer

Answer by andrew-lukasik · Jul 14, 2021 at 10:47 AM


Unity’s Platform Dependent Compilation feature consists of some preprocessor directives that let you partition your scripts to compile and execute a section of code exclusively for one of the supported platforms.


 using UnityEngine;
 #if UNITY_EDITOR
 using UnityEditor;
 #endif
 
 public class TestScript : MonoBehaviour
 {
 
     void Start ()
     {
         #if UNITY_EDITOR
         /// this code will be present in Editor only
         Selection.activeGameObject = transform.root.gameObject;
         Debug.Log(transform.root.gameObject.name+" selected",gameObject);
         #endif
 
         #if DEBUG
         /// this code will be present in Editor AND Debug builds
         Debug.Log("Script started",gameObject);
         #endif
     }
 
     void Update ()
     {
         transform.localScale = Vector3.one + Vector3.one*0.1f*Mathf.Sin(Time.time);
     }
 
     #if UNITY_EDITOR
     void OnDrawGizmos ()
     {
         Gizmos.color = Color.yellow;
         Gizmos.DrawWireCube( transform.position , transform.localScale );
 
         Handles.Label( transform.position , gameObject.name );
     }
     #endif
 
 }
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
0

Answer by DamonD. · Jan 10, 2012 at 07:34 PM

well after digging around a bit i found that i dont have to ignore it and still build the game. i had to place it in an editor script rather than the gameobject script hope this helps someone else.

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 Kavisha26 · Jul 14, 2021 at 09:26 AM 0
Share

I am having this issue. And tried putting the scipt into the Editor folder but then how can I allocate a gameobject to that script. I can't drop it to the hierachy. Sorry im new to this. And would really appreciate help.

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

BCE0044 erro only shows when trying to build .apk 0 Answers

Check for compilation errors in Editor Script 0 Answers

Physics Raycast work fine but don't work after build game. 0 Answers

Why I get this Debug error: 'fileLength == processed' when calling CreatePrefab? 0 Answers

Distribute terrain in zones 3 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