# 7. Day-Night and Weather Pitfalls Part of [[Day-Night Cycle and Weather]]. Prev: [[6. Worked Example Village Day Night Storm]]. ## Lighting | Symptom | Cause | Fix | |---|---|---| | Nights are pitch black | ambient gradient goes to black; moon too dim | keep an ambient floor (~10-15% of noon) and a readable moon; Level Up! readability beats realism | | Shadows pop or double at sunrise | both directional lights cast shadows, or the handover happens while the sun is bright | `SunMoonController` gives shadows to one light; shape curves so both lights are near 0 at the handover | | Sun lights the scene from below the ground | intensity curve not zero below the horizon | sun intensity 0 whenever elevation < 0; use `SunElevation` to check | | Colour temperature does nothing | `GraphicsSettings.lightsUseLinearIntensity` off, or `useColorTemperature` false | turn both on; the controller warns | | Interiors glow at noon | ambient is uniform; no sky occlusion | APV **Sky Occlusion** (Progressive GPU lightmapper) and rebake | | Ambient does not change at all | Environment Source is Skybox (driver writes Trilight colours only) or a baked ambient probe | Source **Gradient**; or Skybox + throttled `DynamicGI.UpdateEnvironment` | | Frame spikes every few seconds | `DynamicGI.UpdateEnvironment` or `ReflectionProbe.RenderProbe` called too often | rate-limit (part 2); one probe per frame; fewer, lower-res probes | | Scenario blend does nothing | Lighting Scenarios / Scenario Blending not enabled in the URP asset, scenario names misspelt, or scenarios baked with different probe layouts | enable both, copy names exactly, rebake all scenarios without moving geometry | | Shiny surfaces reflect a noon sky at night | baked reflection probes | realtime probes refreshed by `ReflectionProbeScheduler`, or dim with `reflectionIntensity` | | Lamps light the room but stealth ignores them | lamp toggled by `SetActive(false)` so `StealthTarget` never found the Light, or lights collected before lamps spawned | toggle `Light.enabled` (as `TimedLamp` does); collect lights after spawning | ## Sky | Symptom | Cause | Fix | |---|---|---| | Skybox is pink or empty | Shader Graph Unlit used as a skybox (not supported in URP), or shader compile error | the hand-written shader from part 3; check the Console for HLSL errors | | Cubemap looks banded or too dark | LDR or RGBM-encoded cubemap without decode | import HDR (BC6H); keep `DecodeHDREnvironment` | | Distant objects look cut out | fog colour does not match the horizon colour | drive both from similar gradients; fog colour close to `horizonColor` | | Sun disc and shadows disagree | the skybox driver read the sun direction before the controller moved it | compute direction from the clock, or order the subscriptions | | The skybox material asset changes in Git after Play Mode | writing to the shared material | `SkyboxDriver` uses a runtime instance | ## Weather and VFX | Symptom | Cause | Fix | |---|---|---| | Rain falls inside houses | depth collision only knows what the camera sees; roofs above an indoor camera are not in the depth buffer | `WeatherInteriorZone` (rate x 0 indoors) or *Kill Shape* blocks around buildings | | Rain collides with itself, flickers | Opaque output writes depth | Alpha or Additive output (VFX Graph manual limitation) | | No collision at all | collision camera disabled or not tagged `MainCamera` | tag the camera or use *Custom* camera | | Rain disappears when you turn | VFX bounds culled | bounds that include the tile box, or recorded bounds; system in World space | | Rain only near the origin | `TileCenter` not set, or Tile/Warp box not bound to it | check the exposed property name matches `TileCenter` exactly (`HasVector3` returns false otherwise) | | Rain is a solid wall | spawn rate x lifetime too high for the box | particles alive = rate x lifetime; 8 000/s x 3 s = 24 000; raise box size before rate | | Weather snaps instead of blending | `transitionSeconds` tiny, or `SetWeather(..., instant: true)` | blend 15-30 s; instant only on load | | Storms appear from a clear sky | Markov table allows Clear -> Storm | storms only from Cloudy/Rain (telegraph) | | Puddles dry instantly | surfaces follow the profile directly | accumulate with separate wetting and drying rates (part 4) | | Lightning hurts | rapid full-screen flashes | accessibility toggle, fewer and softer flashes ([[Accessibility]]) | | Rain audio still loud indoors | `WeatherInteriorZone` trigger never fires | player needs a Rigidbody or CharacterController; zone collider is a trigger; tag matches | ## Time and events | Symptom | Cause | Fix | |---|---|---| | Lamps or shops wrong after sleeping | time set directly, skipping `HourChanged` | `TimeOfDayClock.Skip` / `SkipTo`, which step hour by hour | | Events replayed after loading | load used `Skip` | load with `SetTime` / `Restore` | | Day keeps moving in the pause menu (or stops when you did not want it to) | scaled vs unscaled delta time | decide; the clock uses scaled time ([[4. Pause Menu Time Scale and Audio]]) | | Two clocks, odd flicker | clock in a scene that is loaded additively twice | one clock in a persistent scene; the second disables itself | | Statics survive between Play sessions | domain reload disabled (Enter Play Mode options) | reset statics with `[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]`, as `WeatherInteriorZone` does; `EnemySenses` scales reset in `WeatherStealthBridge.OnDisable` | | Saved weather not restored | profile renamed (saved by asset name) | stable ids in profiles | ## Performance budget (measure, do not trust) Start with these and confirm in the Profiler on the target hardware ([[Profiling and Optimization]]): - Clock and drivers: a handful of `Evaluate` calls per frame; negligible. - Main-light shadows: one directional cascade set at a time. - Realtime reflection probes: rendered rarely, one per frame. - Rain VFX: tens of thousands of GPU particles is typical for VFX Graph on desktop; on low-end or mobile targets use the Particle System fallback with far fewer particles ([[5.VFX Graph Comparison and Performance]], [[6. VFX Graph Performance and Quest]]). - APV scenario blending: `numberOfCellsBlendedPerFrame` trades blend speed for frame time. ## Related pitfalls notes - [[8.Lighting Pitfalls]] - [[7. VFX Graph Pitfalls]] - [[6.Particle Pitfalls]] - [[7. Post-Processing Pitfalls]] ## Sources - VFX Graph 17.5, Collide with Depth Buffer (camera requirement, Opaque limitation): https://docs.unity3d.com/Packages/[email protected]/manual/Block-CollideWithDepthBuffer.html - `DynamicGI.UpdateEnvironment`: https://docs.unity3d.com/6000.5/Documentation/ScriptReference/DynamicGI.UpdateEnvironment.html - APV sky occlusion (6000.5): https://docs.unity.com/en-us/engine/6000.5/manual/lighting-overview/lighting/probevolumes/probe-volumes-change-lighting-at-runtime/skyocclusion - Unity issue 20676: https://issuetracker.unity.com/issues/20676 - `RuntimeInitializeLoadType.SubsystemRegistration`: https://docs.unity3d.com/6000.5/Documentation/ScriptReference/RuntimeInitializeLoadType.SubsystemRegistration.html