Predicted Timer Module
The TimerModule is a built-in module for handling networked countdowns. It manages the synchronization of time between server and client, ensuring that timers roll back correctly during prediction corrections.
Basic Usage
Instantiate the module within your PredictedIdentity. By default, the timer automatically ticks down by delta every simulation tick.
public class Bomb : PredictedIdentity
{
private TimerModule _fuseTimer;
protected override void LateAwake()
{
// Create the timer (default: automatic countdown)
_fuseTimer = new TimerModule(this);
// Hook into events
_fuseTimer.onTimerEnded += Explode;
_fuseTimer.onPredictedTimerUpdated_View += UpdateTimerUI;
}
public void Activate()
{
// Only the server (or owner, if allowed) needs to start it
if (isServer)
_fuseTimer.StartTimer(5.0f);
}
private void Explode() { /* Boom */ }
private void UpdateTimerUI(float timeRemaining)
{
// Use the event value for smooth UI updates
_uiText.text = timeRemaining.ToString("F1");
}
}Manual Ticking
You can disable automatic counting to control the timer manually (e.g., for a charging weapon that only advances while a button is held).
API References
Member
Description
Properties
remaining
The current authoritative time remaining.
isTimerRunning
Returns true if the timer is currently active (value is not null).
predictedViewTimer
The smoothed time value for visual use (Update/LateUpdate).
Methods
StartTimer(float time)
Sets the timer to the specified value and starts it.
StopTimer(bool silent)
Stops the timer. If silent is true, onTimerEnded is not invoked.
TickTimer(float amount)
Manually adjusts the timer by the given amount.
Events
onTimerEnded
Invoked when the timer reaches 0.
onPredictedTimerUpdated_View
Invoked when the visual time changes. Use this for UI.
onVerifiedTimerUpdated_View
Invoked when the authoritative state is updated.
Last updated