Time Control#

By default, Crest uses the current game time given by Time.time when simulating and rendering the water. In some situations it is useful to control this time, such as an in-game pause or to synchronise wave conditions over a network. This is achieved through what we call TimeProviders, and a few use cases are described below.

Note

The Dynamic Waves simulation must progress frame by frame and can not be set to use a specific time, and also cannot be synchronised accurately over a network.

Supporting Pause#

One way to pause time is to set Time.timeScale to 0. In many cases it is desirable to leave Time.timeScale untouched so that animations continue to play, and instead pause only the water. To achieve this, attach a Custom Time Provider component to a GameObject and assign it to Water Renderer ‣ General ‣ Time Provider. Then time can be paused by setting the _paused variable on the Custom Time Provider component to false.

The Custom Time Provider also allows driving any time to the system which may give more flexibility for specific use cases.

A final alternative option is to create a new class that implements the ITimeProvider interface and call WaterRenderer.Instance.PushTimeProvider() to apply it to the system.

Network Synchronisation#

A requirement in networked games is to have a common sense of time across all clients. This can be specified using an offset between the clients Time.time and that of a server.

This is supported by attaching a TimeProviderNetworked.cs component to a GameObject, assigning it to Water Renderer ‣ General ‣ Time Provider, and at run-time setting TimeProviderNetworked.TimeOffsetToServer to the time difference between the client and the server.

If using the Mirror network system, set this property to the network time offset. Crest expects that if the client time is ahead then the offset needs to be a negative value which may mean that you need to invert the sign of the offset first.

If the server needs the water shape to run physics but does not have a GPU then we have a CPU path, see CPU Queries. Different server conditions can be emulated in Editor using the Force Batch Mode and Force No GPU toggles on the Water Renderer.

Note that dynamic waves are not synchronised across the network and should not be relied upon in multiplayer projects.

Timelines and Cutscenes#

One use case for this is for cutscenes/timelines when the waves conditions must be known in advance and repeatable. For this case you may attach a Cutscene Time Provider component to a Game Object and assign it to Water Renderer ‣ General ‣ Time Provider. This component will take the time from a Playable Director component which plays a cutscene Timeline. Alternatively, a Custom Time Provider component can be used to feed any time into the system, and this time value can be keyframed, giving complete control over timing.