Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on March 30, 2023, between 5 am & 1 pm EST, in the Performance Profiling Dev Blitz Day 2023 - Q&A forum and Discord where you can connect with our teams behind the Memory and CPU Profilers.
    Dismiss Notice

Question Why is OnValidate not stripped from builds?

Discussion in 'Editor & General Support' started by Aka_ToolBuddy, Jan 30, 2023.

  1. Aka_ToolBuddy

    Aka_ToolBuddy

    Joined:
    Feb 25, 2014
    Posts:
    486
  2. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    4,040
    Well the docs don't say anything about it being an 'editor only build method' it states it's only called in the editor.

    None of Unity's magic methods are stripped out from builds, including editor-centric ones like OnDrawGizmos. If you don't want it in a build, surround it in
    #if UNITY_EDITOR
    pre-processor directives, like normal.
     
  3. Aka_ToolBuddy

    Aka_ToolBuddy

    Joined:
    Feb 25, 2014
    Posts:
    486
    Hi @spiney199. Thanks for your answer.

    That's what I do already, but I was wondering why making this needed in the first place.

    True, but my question was why "only called in the editor" would not lead to "editor only build method".

    I find that it is a missed opportunity from Unity to reduce build sizes.

    I get that changing in the future the default behavior (to make unity strip these methods) might break existing projects, thus making this decision a bad one. But I think that allowing this behavior as part of Managed Code Stripping set to high (which is aggressive already to the point of potentially breaking projects) can be a good idea. That way, people wanting minimal builds at all cost can benefit from this behavior.
     
  4. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    4,040
    Code is, by a country mile, the tiniest part of a build. I doubt stripping a few lines is going to make a noticeable difference. A single texture file could easily outsize all your .dll files.

    Extensive validation, gizmos, etc, should be handled with custom editors anyway. That way none of them will make it into a build.
     
    Kurt-Dekker likes this.