Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    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:
    536
  2. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,606
    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.
     
    Samwall likes this.
  3. Aka_ToolBuddy

    Aka_ToolBuddy

    Joined:
    Feb 25, 2014
    Posts:
    536
    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:
    7,606
    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.