RUSTICDOCSSearch documentation

Change the environment from scripts

Back to Sky & atmosphere.

All ten scripting adapters expose Game.scene.getEnvironment(), Game.scene.setEnvironment(settings) and Game.scene.setSkyTexture(path). These calls target the loaded scene, including from global startup scripts, scene startup scripts, and object component scripts. They work in Play, Play Solo and Run. CSS-only assets have no executable callbacks; HTML uses inline JavaScript.

  1. Copy both daytime and nighttime 2:1 panoramas into your project, for example assets/skies/day.hdr and assets/skies/night.hdr, before starting Play. Runtime scripts use the immutable play snapshot; they cannot download an image or select a file outside it.
  2. Create a Lua script using Explorer's scripting commands. Attach it as a Scene Startup Script for the scene, or select an object and use + Add Component to attach the script. See the language guides for other languages and their toolchains.
  3. Use the following script and start Play with an active camera and visible geometry:
lua
return {
  Start = function()
    Game.scene.setEnvironment({
      enabled = true,
      sky_image = 'assets/skies/day.hdr',
      rotation_degrees = 45,
      exposure = 0,
      ambient_color = {1, 1, 1},
      ambient_intensity = 0.12,
      sun_color = {1, 0.95, 0.85},
      sun_intensity = 1,
      sun_direction = {0.3, 0.8, 0.4},
      haze_color = {0.6, 0.7, 0.8},
      haze_density = 0.01,
      haze_start = 20
    })
    print(Game.scene.getEnvironment().sky_image)
  end
}

The next game frame shows the daytime sky, sun lighting and distance haze. The console prints assets/skies/day.hdr. To switch skies during a later callback:

lua
Game.scene.setSkyTexture('assets/skies/night.hdr')
Game.scene.setEnvironment({sun_intensity = 0, ambient_intensity = 0.06})

setEnvironment applies a partial update: omitted fields keep their current values. It validates the entire resulting environment and applies all supplied fields atomically. Unknown fields, wrong types and invalid values raise a script error without changing the environment. getEnvironment returns a fresh copy of the live settings; editing that copy alone has no effect. Reads immediately see successful updates, including earlier updates from other scripts. Nine adapters return all settings from setters too; C setters return void.

setSkyTexture changes only sky_image; it does not enable a disabled environment or change lighting. Use an empty string to clear the panorama and show the configured solid or daylight sky. Set enabled=false to return to the built-in 3D sky and default lighting. Set sky_hidden=true to hide the sky and clouds. These runtime changes do not save back to the editor scene or appear in Apply Runtime Changes. Stop and restart Play to restore the editor's settings.

SettingType and accepted values
enabledBoolean. Enables the custom sky, scene ambient light, sun light and haze.
sky_hiddenBoolean, false by default. True hides the sky and clouds.
sky_proceduralBoolean, false by default. In a custom environment with an empty sky_image, true uses daylight and false uses sky_color.
clouds_enabledBoolean, false by default. Enables the volumetric layer independently of enabled.
cloud_coverageNumber from 0 to 1, defaults to 0.55. Zero gives a clear sky.
cloud_densityNumber from 0 to 4, defaults to 1. Controls opacity. Zero gives a clear sky.
cloud_altitudeNumber from -100,000 to 100,000, defaults to 180. Layer base along world Y.
cloud_thicknessNumber from 1 to 20,000, defaults to 90. Layer depth in world units.
cloud_scaleNumber from 1 to 20,000, defaults to 240. Size of cloud features in world units.
sky_imageProject-relative HDR, PNG, JPEG or TGA path with / separators; empty clears it. Absolute paths, backslashes, drive prefixes, empty path segments, . and .. are rejected.
sky_colorThree finite, non-negative RGB numbers. Used for a solid custom sky.
rotation_degreesFinite panorama rotation in degrees.
exposureFinite sky-image exposure in stops, from -20 to 20.
ambient_colorThree finite, non-negative RGB numbers.
ambient_intensityFinite, non-negative ambient strength.
sun_colorThree finite, non-negative RGB numbers.
sun_intensityFinite, non-negative directional light strength.
sun_directionThree finite numbers pointing from a surface towards the sun; squared length must exceed 0.000001 and remain finite.
haze_colorThree finite, non-negative RGB numbers.
haze_densityFinite, non-negative density; zero disables haze.
haze_startFinite, non-negative starting distance in world units.
windA partial object with enabled, strength (two speeds from 0 to 100 m/s), and direction (two clockwise bearings from 0° to 360°). Null removes Wind. Read live world-space velocity with getEnvironment("wind_velocity").
timeOptional partial object when updating. Fields are enabled (default false), start_hour (0–24, default 12), cycle_seconds (1–86,400, default 120), sky_turns_per_day (integer from -8 to 8, default 1) and project-relative night_image, sunrise_image and sunset_image paths. Use an empty string to clear a phase image.

Script adapters that accept settings objects can change the cycle using a partial time object. For example, from JavaScript:

js
Game.scene.setEnvironment({
  enabled: true,
  time: { enabled: true, start_hour: 18, cycle_seconds: 24 }
});

getEnvironment().time returns the configured values. The rendered clock adds elapsed gameplay time to start_hour, so a change mid-session uses the time already elapsed. The C field API uses scalar values. Configure the cycle in the editor for C projects.

Colors may exceed 1 for HDR lighting. Values must fit the engine's 32-bit float representation. Sky rotation does not rotate the sun. The sky remains a background, so changing it does not generate reflections or image-based lighting.