- Home /
Is OnDrawGizmos called in build?
Simple question but couldn't seem to locate a definitive answer… Are functions like OnDrawGizmos or OnDrawGizmosSelected ever called when running a build? I assume they only run inside the editor in scene view but I just want to be sure! I have an OnDrawGizmos helper function that's doing a lot of GameObject.Find and would be disastrous if it runs in the build. :)
Answer by Bunny83 · Jan 06, 2014 at 06:52 PM
No, they won't be executed in a build
Is is still linked like all the other functions? ( unless you exclude it with #if UNITY_EDITOR )
@Rs: Yes of course. Unity uses the more or less unchanged $$anonymous$$ono compiler (C# and boo. The UnityScript compiler is build on top of the boo compiler).
So it's usually the best to wrap them with preprocessor tags to exclude it from the build just as you mentioned.
Answer by IggyZuk · Jul 09, 2020 at 11:29 PM
You can also use the Conditional attribute to make sure the function is excluded from the build:
[Conditional("UNITY_EDITOR")]
void OnDrawGizmos()
{
// ...
}
It's the same as:
#if UNITY_EDITOR
void OnDrawGizmos()
{
// ...
}
#endif
Your answer
Follow this Question
Related Questions
Game runs fine first time but lags when stopped and started in editor. 1 Answer
What's the best way to make a long scrolling list of items? 0 Answers
FPS decreases over time in editor (Potential memory leak?) 2 Answers
Why does asset import take so long? 0 Answers
Efficient sprite sheet animation with Editor preview 0 Answers