Why is OnValidate not stripped from builds?

Hi
The documentation of OnValidate states that it is an editor only build method.

Is there any reason all the OnValidates in a project are still included in the builds, even with Managed Code Stripping set to high?
Thanks

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.

1 Like

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.

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.

1 Like