Script not running in game build

I have a Day & Night system that works as expected in the editor but doesn’t in the build, I use OnValidate() so I can adjust settings in the editor. If I comment out the OnValidate() it stops working in the editor as well when I play it.

  1. Play in editor, see it work
  2. Build and see it not work

I’m using HDRP, here is a link to a bare project with my demo in it.
My Project

I hope someone can help, I tried to go straight to Unity support but I don’t see that option unless paying for it.

Script only
Script.cs (6.2 KB)

Upload the script.
OnValidate is only for editor variables (changes in Inspector)

I understand that, the problem is when I build the project the day night cycle never starts. I commented out the OnValidate() thinking that might be the problem before building, but regardless of it being commented out or not things don’t work. (I’m not trying to alter setting in the built game)

I only mentioned OnValidate() because when playing the game in the editor the day night cycle works as expected but when I build the project the day night cycle never starts.

This just sounds like a bog-standard “it dudn’t work in build” bug, something that has an infinite number of causes and solutions.

It just means… time for you to start debugging!

By debugging you can find out exactly what your program is doing so you can fix it.

Use the above techniques to get the information you need in order to reason about what the problem is.

You can also use Debug.Log(...); statements to find out if any of your code is even running. Don’t assume it is.

Once you understand what the problem is, you may begin to reason about a solution to the problem.

Remember with Unity the code is only a tiny fraction of the problem space. Everything asset- and scene- wise must also be set up correctly to match the associated code and its assumptions.

Is there a way to log debug messages in the built game or do they get stripped when compiling?

They get written to a text file. Google Unity log location
You can also enable the debug build checkbox and then you can even connect the build to the editor

I’ll try the enable debug build checkbox, never used it so now is as good a time as any. Thanks.

1 Like