Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

onValidate called on the build step

Discussion in '2019.3 Beta' started by 00christian00, Jan 20, 2020.

  1. 00christian00

    00christian00

    Joined:
    Jul 22, 2012
    Posts:
    1,035
    Is it normal that now with 2019.3 onValidate gets called at build time for each scene?
    It is quite annoying and have to revise a lot of code.
     
  2. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,619
    If the behavior has changed between versions, then you probably found a regression. In this case, please submit a bug-report and leave the Case number here for Unity staff to pick up.
     
  3. 00christian00

    00christian00

    Joined:
    Jul 22, 2012
    Posts:
    1,035
    Before doing a bug report which is quite time consuming(unless it is fine without repro project) I want to know if it is expected.
    I have already some bugs report open since many years, so I would like to avoid reporting if not absolutely necessary.
     
  4. SteenLund

    SteenLund

    Unity Technologies

    Joined:
    Jan 20, 2011
    Posts:
    639
    I am pretty sure this has not changed and OnValidate has always been called each time a scene was opened during player building.

    So I am curious what you have noticed as a change?
     
  5. 00christian00

    00christian00

    Joined:
    Jul 22, 2012
    Posts:
    1,035
    Strange. I have some script doing procedural generation on onValidate because I didn't bother to create an editor script, but I never noticed its messages while doing a build.
    Maybe before I had just regular message, while now I introduced some error messages?
    It's really strange I never noticed it, because some of them are quite verbose.
    Maybe before you weren't showing the messages on the console?
     
  6. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Well, if the object isn't currently active and loaded, it won't trigger so perhaps that's why you didn't see it before. It has always happened to me though, when building a scene with such an object present.

    (And it should fire because during build, developers are able to run a number of scripts and utilities to change the output that gets built, though I haven't personally used OnValidate for these purposes)
     
    00christian00 likes this.
  7. 00christian00

    00christian00

    Joined:
    Jul 22, 2012
    Posts:
    1,035
    If you guys say so I believe it.
    Why it need to get called every time btw?
     
  8. SteenLund

    SteenLund

    Unity Technologies

    Joined:
    Jan 20, 2011
    Posts:
    639
    It is done every time a scene is loaded or a prefab asset is loaded, to ensure the scene is in a valid state. Imagine a bad merge of a scene causing dangling components or broken transform hierarchies, if we simply ignore that during the build process it would be pretty bad.
     
    00christian00 likes this.