- Home /
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.
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
}
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.
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
![](https://koobas.hobune.stream/wayback/20220613062831im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
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