Class CooldownController
Controls and manages ability cooldowns using immutable CooldownInstance
based on StartTick + DurationTicks. No per-tick mutation — cooldowns expire
automatically via integer comparison: (currentTick - StartTick) >= DurationTicks.
public class CooldownController : CharacterBehaviour, ICooldownController, ICharacterBehaviour, IPredictableController
- Inheritance
-
ObjectComponentBehaviourMonoBehaviourNetworkBehaviourCooldownController
- Implements
- Inherited Members
-
NetworkBehaviour.IsSpawnedNetworkBehaviour.ComponentIndexNetworkBehaviour.NetworkObjectNetworkBehaviour.MAXIMUM_NETWORKBEHAVIOURSNetworkBehaviour.UNSET_NETWORKBEHAVIOUR_IDNetworkBehaviour.ToString()NetworkBehaviour.Reset()NetworkBehaviour.OnValidate()NetworkBehaviour.IsBehaviourReconcilingNetworkBehaviour.ClearReplicateCache()NetworkBehaviour.CreateReconcile()NetworkBehaviour.Reconcile_Reader<T>(PooledReader, ref T)NetworkBehaviour.OnStartServerCalledNetworkBehaviour.OnStartClientCalledNetworkBehaviour.WritePayload(NetworkConnection, Writer)NetworkBehaviour.ReadPayload(NetworkConnection, Reader)NetworkBehaviour.OnStopNetwork()NetworkBehaviour.OnStartServer()NetworkBehaviour.OnStopServer()NetworkBehaviour.OnOwnershipServer(NetworkConnection)NetworkBehaviour.OnSpawnServer(NetworkConnection)NetworkBehaviour.OnDespawnServer(NetworkConnection)NetworkBehaviour.OnStartClient()NetworkBehaviour.OnStopClient()NetworkBehaviour.OnOwnershipClient(NetworkConnection)NetworkBehaviour.ClearBuffedRpcs()NetworkBehaviour.ExcludeOwnerFromUnbufferedObserversRpcsNetworkBehaviour.IsClientOnlyNetworkBehaviour.IsServerOnlyNetworkBehaviour.IsHostNetworkBehaviour.IsClientNetworkBehaviour.IsServerNetworkBehaviour.IsDeinitializingNetworkBehaviour.NetworkManagerNetworkBehaviour.ServerManagerNetworkBehaviour.ClientManagerNetworkBehaviour.ObserverManagerNetworkBehaviour.TransportManagerNetworkBehaviour.TimeManagerNetworkBehaviour.SceneManagerNetworkBehaviour.PredictionManagerNetworkBehaviour.RollbackManagerNetworkBehaviour.NetworkObserverNetworkBehaviour.IsClientInitializedNetworkBehaviour.IsClientStartedNetworkBehaviour.IsClientOnlyInitializedNetworkBehaviour.IsClientOnlyStartedNetworkBehaviour.IsServerInitializedNetworkBehaviour.IsServerStartedNetworkBehaviour.IsServerOnlyInitializedNetworkBehaviour.IsServerOnlyStartedNetworkBehaviour.IsHostInitializedNetworkBehaviour.IsHostStartedNetworkBehaviour.IsOfflineNetworkBehaviour.IsNetworkedNetworkBehaviour.GetIsNetworked()NetworkBehaviour.IsManagerReconcilingNetworkBehaviour.ObserversNetworkBehaviour.IsOwnerNetworkBehaviour.IsControllerNetworkBehaviour.HasAuthorityNetworkBehaviour.OwnerNetworkBehaviour.OwnerIdNetworkBehaviour.ObjectIdNetworkBehaviour.LocalConnectionNetworkBehaviour.OwnerMatches(NetworkConnection)NetworkBehaviour.Despawn(GameObject, DespawnType?)NetworkBehaviour.Despawn(NetworkObject, DespawnType?)NetworkBehaviour.Despawn(DespawnType?)NetworkBehaviour.Spawn(GameObject, NetworkConnection, Scene)NetworkBehaviour.Spawn(NetworkObject, NetworkConnection, Scene)NetworkBehaviour.RemoveOwnership()NetworkBehaviour.GiveOwnership(NetworkConnection)NetworkBehaviour.GetInstance<T>()NetworkBehaviour.TryRegisterInstance<T>(T)NetworkBehaviour.UnregisterInstance<T>()NetworkBehaviour.CanLog(LoggingType)MonoBehaviour.IsInvoking()MonoBehaviour.CancelInvoke()MonoBehaviour.StopCoroutine(Coroutine)MonoBehaviour.StopAllCoroutines()MonoBehaviour.destroyCancellationTokenMonoBehaviour.useGUILayoutMonoBehaviour.didStartMonoBehaviour.didAwakeMonoBehaviour.runInEditModeBehaviour.enabledBehaviour.isActiveAndEnabledComponent.GetComponent<T>()Component.TryGetComponent<T>(out T)Component.GetComponentInChildren<T>()Component.GetComponentsInChildren<T>()Component.GetComponentInParent<T>()Component.GetComponentsInParent<T>()Component.GetComponents<T>()Component.GetComponentIndex()Component.CompareTag(TagHandle)Component.transformComponent.transformHandleComponent.gameObjectComponent.tagObject.GetEntityId()Object.GetInstanceID()Object.GetHashCode()Object.InstantiateAsync<T>(T)Object.InstantiateAsync<T>(T, Transform)Object.InstantiateAsync<T>(T, Vector3, Quaternion)Object.InstantiateAsync<T>(T, Transform, Vector3, Quaternion)Object.Instantiate(Object, Vector3, Quaternion)Object.Instantiate(Object, Vector3, Quaternion, Transform)Object.Instantiate(Object)Object.Instantiate(Object, Scene)Object.Instantiate<T>(T, InstantiateParameters)Object.Instantiate<T>(T, Vector3, Quaternion, InstantiateParameters)Object.Instantiate(Object, Transform)Object.Instantiate<T>(T)Object.Instantiate<T>(T, Vector3, Quaternion)Object.Instantiate<T>(T, Vector3, Quaternion, Transform)Object.Instantiate<T>(T, Transform)Object.Destroy(Object)Object.DestroyImmediate(Object)Object.DontDestroyOnLoad(Object)Object.DestroyObject(Object)Object.FindObjectsOfType<T>()Object.FindObjectsByType<T>(FindObjectsSortMode)Object.FindObjectsByType<T>(FindObjectsInactive, FindObjectsSortMode)Object.FindObjectOfType<T>()Object.FindFirstObjectByType<T>()Object.FindAnyObjectByType<T>()Object.FindFirstObjectByType<T>(FindObjectsInactive)Object.FindAnyObjectByType<T>(FindObjectsInactive)Object.FindObjectsByType<T>()Object.FindObjectsByType<T>(FindObjectsInactive)Object.nameObject.hideFlags
Properties
Order
Execution order in the unified prediction pipeline. Runs before AbilityController so newly elapsed cooldowns are removed before ability start checks in the same tick.
public int Order { get; }
Property Value
Methods
AddCooldown(long, CooldownInstance)
Adds a cooldown for the specified ability.
public void AddCooldown(long id, CooldownInstance cooldown)
Parameters
idlongAbility ID.
cooldownCooldownInstanceCooldown instance.
Clear()
Clears all cooldowns.
public void Clear()
CreateReconcileSnapshot()
Creates a reconcile snapshot of all active cooldowns. Returns the cached array when cooldowns haven't changed since the last call. Returns null when no cooldowns are active.
public CooldownReconcileEntry[] CreateReconcileSnapshot()
Returns
Remarks
Always allocates a fresh array when dirty, even if the length matches. The delta serializer holds a reference to the previous tick's snapshot; mutating in-place would silently update that reference, making prev == next and masking the change (zero bytes sent when bytes should have been sent).
ExpireElapsed(uint)
public void ExpireElapsed(uint currentTick)
Parameters
currentTickuint
IsOnCooldown(long, uint)
Checks if an ability is on cooldown at the given tick.
public bool IsOnCooldown(long id, uint currentTick)
Parameters
Returns
- bool
True if on cooldown, otherwise false.
OnCreateReconcile(ref CharacterReconcileData)
Writes cooldown reconcile state for this tick.
public void OnCreateReconcile(ref CharacterReconcileData reconcileData)
Parameters
reconcileDataCharacterReconcileDataMutable unified reconcile payload.
OnReconcile(CharacterReconcileData, Channel)
Restores cooldowns from authoritative reconcile state.
public void OnReconcile(CharacterReconcileData rd, Channel channel)
Parameters
rdCharacterReconcileDataUnified reconcile payload.
channelChannelTransport channel.
Remarks
The owner always reconciles — this is the authority for its own cooldown simulation, and the correction that removes a cooldown it mispredicted.
A non-owner only reconciles a forwarded object, because that is the only mode in which
it runs the ability simulation at all and therefore the only mode in which a peer's
cooldowns mean anything to it. With forwarding off an observer never receives this
reconcile, so the guard states the contract rather than defending against a message that
cannot arrive — and it keeps the reconcile path aligned with what the spawn payload
already decided: AbilityController.WritePayload writes the cooldown block with
includeEntries: isOwner, framed with a zero count for everyone else, because
observers never read a peer's cooldowns. Without this guard the two paths disagreed about
the same fact the moment forwarding was switched on. See ObserverSyncMode.
OnReplicate(ref CharacterReplicateData, ReplicateState, Channel)
Expires elapsed cooldowns deterministically for the current prediction tick.
public void OnReplicate(ref CharacterReplicateData input, ReplicateState state, Channel channel)
Parameters
inputCharacterReplicateDataUnified replicate input containing the network tick.
stateReplicateStateCurrent replicate execution state.
channelChannelTransport channel.
OnStartNetwork()
Called when the network has initialized this object. May be called for server or client but will only be called once. When as host or server this method will run before OnStartServer. When as client only the method will run before OnStartClient.
public override void OnStartNetwork()
PopulateInput(ref CharacterReplicateData)
Cooldowns do not contribute owner input into CharacterReplicateData.
public void PopulateInput(ref CharacterReplicateData input)
Parameters
inputCharacterReplicateDataUnified replicate data for this tick.
Read(Reader, uint)
Reads cooldown data from a network reader.
public void Read(Reader reader, uint currentTick)
Parameters
readerReaderThe network reader.
currentTickuintCurrent tick for computing UI-facing remaining time.
RemoveCooldown(long)
Removes the cooldown for the specified ability.
public void RemoveCooldown(long id)
Parameters
idlongAbility ID.
ResetState(bool)
Resets this NetworkBehaviour so that it may be added to an object pool.
public override void ResetState(bool asServer)
Parameters
asServerbool
ResolveAuthoritativeTick(uint)
Maps a raw authoritative tick to the current replicate-domain tick when available.
public uint ResolveAuthoritativeTick(uint serverTick)
Parameters
serverTickuintFallback authoritative tick.
Returns
- uint
The current replicate-domain tick if one can be derived, otherwise
serverTick.
RestoreFromReconcile(CooldownReconcileEntry[])
Restores cooldown state from a reconcile snapshot, replacing current entries only when they differ.
public void RestoreFromReconcile(CooldownReconcileEntry[] entries)
Parameters
entriesCooldownReconcileEntry[]
TryGetCooldown(long, uint, out float)
Tries to get the remaining cooldown time in seconds for an ability.
public bool TryGetCooldown(long id, uint currentTick, out float cooldown)
Parameters
idlongAbility ID.
currentTickuintThe current network tick.
cooldownfloatRemaining cooldown time in seconds.
Returns
- bool
True if found and still on cooldown, otherwise false.
TryGetCooldownInstance(long, out CooldownInstance)
Tries to get the full cooldown instance for an ability or consumable.
public bool TryGetCooldownInstance(long id, out CooldownInstance instance)
Parameters
idlongAbility or consumable template ID.
instanceCooldownInstanceThe cooldown instance.
Returns
- bool
True if a cooldown is tracked for the id.
Write(Writer)
Writes cooldown data to a network writer. Wire format: uint payloadReferenceTick, int count, then per cooldown: long abilityID, uint startTick, uint durationTicks.
public void Write(Writer writer)
Parameters
writerWriterThe network writer.
Remarks
This is a payload / initial-sync path. See Read(Reader, uint) remarks.
Write(Writer, bool)
Writes cooldown data, optionally as an empty block.
public void Write(Writer writer, bool includeEntries)
Parameters
writerWriterThe network writer.
includeEntriesboolFalse to write an empty, still-framed block.
Remarks
includeEntries is false for connections that are not this
character's owner. Cooldowns gate the owner's own activations and drive the owner's
hotkey bar; an observer never reads a peer's — IsOnCooldown is only consulted
inside the caster's own replicate, which observers do not run for peers. The one case
where an observer does run it, forwarded mode, is served by the absolute reconcile
FishNet sends on the tick an observer is added, which carries the cooldown array.
Writing the same framed block with a zero count keeps Read(Reader, uint) unchanged.