Changing settings at runtime¶
Every module reads its settings asset live, so a script can change values at runtime:
using TheyCallMeAlfred.Fable;
using UnityEngine;
public class GrassAmountOption : MonoBehaviour
{
[SerializeField] FableSystem rig;
void Start()
{
// Work on a copy, or Play mode edits are saved into the project's asset.
rig.grassQuality = Instantiate(rig.grassQuality);
}
public void SetGrassAmount(float share) => rig.grassQuality.densityScale = share;
}
Settings assets are assets: in the editor, a change made in Play mode stays in the asset
after you stop. Swap in a copy made with Instantiate first, as above, the way the Core
Demos do.
Most values apply on the next frame. Some only apply when grass is built: anything under
Density, Blade, Size, Orientation and Placement, the surfaces, and the
wind direction that blades face around. After changing those from a script, call
GrassInstancer.RefreshFromSettings() (or BuildNow() when only the blades changed) on each
affected patch. FableSystem.GetGrassPatches() lists every patch under the rig.
To drive the time of day from a script, set timeOfDay on the Skybox settings (with
animateCycle off). SkyboxModule.CurrentTimeOfDay reports the time actually shown,
including while the cycle runs.