Change the Weather at Runtime
intermediate tasksGlobal Snow & Rain 3 · Common Tasks
The weather of Global Snow is set by four values of the Weather block: Temperature and Intensity set what falls from the sky and how much, Snow sets the snow on the ground and Puddles the standing water. This guide shows how to change them from the inspector, from a script, and smoothly over time.
Weather Settings in the Inspector
- Select the camera that has the Global Snow component.
- In the Weather block at the top, set Temperature (°C). Snow falls up to -2 °C, wet snow up to +1 °C, snow and rain mixed up to +3 °C, and rain above.
- Set Intensity, from 0 (none) to 5 (extreme). The Precipitation row shows the name of what falls, for example Medium Wet Snow or Rain Storm.
- Set Snow for the snow on the ground and Puddles for the standing water. Temperature does not melt the snow on the ground.
- If needed, fine-tune Snowfall, Snow Dust, Frost, Rain and the other effects in their foldouts. Your changes stay until Temperature or Intensity moves again.
See Weather in Parameters.
Weather Changes from Scripts
- Call
SetPrecipitation()onGlobalSnow.instancewith the temperature in °C and the intensity from 0 to 5. It gives the same result as the Temperature and Intensity sliders. - Set your own values right after the call, for example a stronger frost on the camera.
- Set
snowAmountfor the snow on the ground andpuddleAmountfor the standing water.
GlobalSnow snow = GlobalSnow.instance;
snow.SetPrecipitation(temperature: -8f, intensity: 4f);
snow.cameraFrostIntensity = 0.8f;
snow.snowAmount = 1f;
snow.puddleAmount = 0f;
These changes apply at once. To blend them over time, see the next section. See Weather Changes in Scripting Support for a complete example.
Gradual Changes and Seasons
A Global Snow Profile stores the weather and most other settings of Global Snow. Blend from one profile into another for smooth weather changes and seasons.
- Create a profile for each weather or season. Click Create next to the Profile field to make one from the current settings, or use Create > Global Snow Profile in the Project window. Select the profile to change its settings.
- From a script, call
TransitionTo(profile, duration)on Global Snow. It blends the current settings into the profile over that time in seconds. Without a duration or outside Play mode, the profile applies at once. A new call starts from the settings at that moment, and the profile is not assigned to Global Snow. - To change only a few settings, make a profile with
GlobalSnowProfile.FromCurrent(), change what you need and pass it to TransitionTo.
GlobalSnow snow = GlobalSnow.instance;
GlobalSnowProfile storm = GlobalSnowProfile.FromCurrent(snow);
storm.SetPrecipitation(temperature: -8f, intensity: 4f);
snow.TransitionTo(storm, duration: 10f);
To drive the blend yourself, for example from the day of a season, use GlobalSnowProfile.Lerp(). A value of 0 applies the first profile and 1 the second one. Snowfall, Running Drops, Camera Frost and Snow Accumulation fade in and out. Other options that cannot blend, like toggles and textures, switch at 0.5.
GlobalSnowProfile.Lerp(GlobalSnow.instance, autumnProfile, winterProfile, t);
See Profiles for what a profile stores, and Season Transitions with Profiles for a complete example.
Snow Accumulation and Melting
The Snow slider sets how much snow covers the ground: from 0 to 1 the snow fades in, and from 1 to 2 it grows thicker. Below 1 the Snow Accumulation also gets thinner. Temperature does not change it, so the snow builds up or melts only when Snow changes.
- To melt the snow, blend into a profile with Snow at 0. Raise Snow Wetness in that profile, so the snow looks wet while it melts.
- To cover the ground with new snow, blend into a profile with Snow at 1 or more and Snow Wetness at 0, and with snow falling.
- Use a long duration, such as one or two minutes, for a slow change.
using UnityEngine;
using GlobalSnowEffect;
public class SnowCycle : MonoBehaviour {
public float duration = 120f;
public void Melt() {
GlobalSnowProfile melted = GlobalSnowProfile.FromCurrent(GlobalSnow.instance);
melted.snowAmount = 0f;
melted.wetness = 1f;
GlobalSnow.instance.TransitionTo(melted, duration);
}
public void SnowAgain() {
GlobalSnowProfile snowy = GlobalSnowProfile.FromCurrent(GlobalSnow.instance);
snowy.SetPrecipitation(temperature: -5f, intensity: 2f);
snowy.snowAmount = 1f;
snowy.wetness = 0f;
GlobalSnow.instance.TransitionTo(snowy, duration);
}
}
When Snow reaches 0, the Deep Marks are cleared, so the new snow grows without the old marks.
Rain Without Snow
- Set Temperature above +3 °C and Intensity above 0, so only rain falls.
- Set Snow to 0, so no snow stays on the ground.
- Set Puddles for the standing water. It works on its own, so the puddles can stay after the rain stops.
GlobalSnow snow = GlobalSnow.instance;
snow.SetPrecipitation(temperature: 8f, intensity: 3f);
snow.snowAmount = 0f;
snow.puddleAmount = 0.6f;
See Rain and Puddles in Rain & Water.
Local Weather Areas
Global Snow has one weather for the whole scene. To use another weather inside an area, such as a valley with rain or a mountain top with a snow storm, blend into another profile when the player enters the area and back when the player leaves it.
- Create two profiles with the Create button next to the Profile field, so both start from your settings. Change the weather of the one for the inside of the area.
- Add a collider that covers the area to an empty GameObject and turn on Is Trigger.
- Add a script like the one below to that GameObject and assign the two profiles. Unity calls the trigger events when the player has a Rigidbody or a Character Controller.
using UnityEngine;
using GlobalSnowEffect;
// another weather while the player is inside this trigger
public class WeatherArea : MonoBehaviour {
public GlobalSnowProfile insideProfile;
public GlobalSnowProfile outsideProfile;
public float duration = 3f;
public string playerTag = "Player";
void OnTriggerEnter(Collider other) {
if (other.CompareTag(playerTag)) GlobalSnow.instance.TransitionTo(insideProfile, duration);
}
void OnTriggerExit(Collider other) {
if (other.CompareTag(playerTag)) GlobalSnow.instance.TransitionTo(outsideProfile, duration);
}
}
Roofs already keep the snowfall, the rain and the puddles out of buildings, see Remove Snow Under Roofs and Inside Buildings.
Next Steps
- Rain & Water - rain, wetness, puddles and running drops.
- Scripting Support (C#) - code examples for the weather and the seasons.
Suggest an improvement
Help us improve this documentation page.