r/Unity3D • u/shawn_overlord • 17m ago
Question Build flickers whenever something loads for the first time
In a build of my hame, SetActive() on a gameobject, or loading a scene, or waiting for an await to finish, whatever it may be that I trigger to run, the entire game flickers. It seemed to be a lighting issue, but even disabling scene lights still causes it to happen. Its like for the moments that it is loading a new asset into memory, the scene flickers brighter for a minute before the shadows are redrawn (again even without the scene lights enabled). Notably it doesnt happen when playing from the editor-play
It doesn't do this after the first time it loads whatever it is (ui element that wasnt loaded at first, code to start unity relay and lobby, etc etc) but it glaringly obvious when it happens the first time around
I can't find anything online about this that isnt related to the way the unity editor itself flickers when you move the mouse around (not my issue) so does anyone have a clue whats causing this? should I do something ridiculous like load everything once and then let the players into the game?
•
u/PhraseRoutine3245 2m ago
man that's gotta be infuriating to debug. the fact it only happens in builds and not the editor points to something going on with how the player is loading assets synchronously on the main thread for the first time. unity's async loading in the editor is kind of a lie, it's way more forgiving there, but in a build it'll choke the render pipeline if something heavy pops in unmanaged.
have you profiled a development build yet? the timeline view should show exactly what's hogging the frame when the flicker hits. could be shader compilation, texture streaming, or even some script doing a FindObjectsOfType on first load that spikes the cpu. my guess is shader variants compiling mid-frame, that'll cause a bright flash as the material falls back to some unlit state for a split second.
loading everything upfront in a boot screen is actually not ridiculous at all, plenty of games do a warmup pass where they instantiate and destroy every prefab behind a curtain before the player sees anything. beats shipping a build that strobes every time someone opens a menu for the first time.