Class NetworkVariable<T>
A variable that can be synchronized over the network.
Implements
Inherited Members
Namespace: Unity.Netcode
Assembly: Unity.Netcode.Runtime.dll
Syntax
[Serializable]
[GenerateSerializationForGenericParameter(0)]
public class NetworkVariable<T> : NetworkVariableBase, IDisposable
Type Parameters
Name | Description |
---|---|
T | the unmanaged type for Network |
Constructors
NetworkVariable(T, NetworkVariableReadPermission, NetworkVariableWritePermission)
Constructor for Network
Declaration
public NetworkVariable(T value = default, NetworkVariableReadPermission readPerm = NetworkVariableReadPermission.Everyone, NetworkVariableWritePermission writePerm = NetworkVariableWritePermission.Server)
Parameters
Type | Name | Description |
---|---|---|
T | value | initial value set that is of type T |
Network |
readPerm | the Network |
Network |
writePerm | the Network |
Fields
CheckExceedsDirtinessThreshold
Declaration
public NetworkVariable<T>.CheckExceedsDirtinessThresholdDelegate CheckExceedsDirtinessThreshold
Field Value
Type | Description |
---|---|
Network |
OnValueChanged
The callback to be invoked when the value gets changed
Declaration
public NetworkVariable<T>.OnValueChangedDelegate OnValueChanged
Field Value
Type | Description |
---|---|
Network |
Properties
Value
The value of the NetworkVariable container
Declaration
public virtual T Value { get; set; }
Property Value
Type | Description |
---|---|
T |
Methods
Dispose()
Virtual IDisposable implementation
Declaration
public override void Dispose()
Overrides
ExceedsDirtinessThreshold()
Check whether or not this variable has changed significantly enough to send an update.
If not, no update will be sent even if the variable is dirty, unless the time since last update exceeds
the Update
Declaration
public override bool ExceedsDirtinessThreshold()
Returns
Type | Description |
---|---|
bool |
Overrides
~NetworkVariable()
Declaration
protected ~NetworkVariable()
IsDirty()
Gets Whether or not the container is dirty
Declaration
public override bool IsDirty()
Returns
Type | Description |
---|---|
bool | Whether or not the container is dirty |
Overrides
OnInitialize()
Called on initialization
Declaration
public override void OnInitialize()
Overrides
ReadDelta(FastBufferReader, bool)
Reads value from the reader and applies it
Declaration
public override void ReadDelta(FastBufferReader reader, bool keepDirtyDelta)
Parameters
Type | Name | Description |
---|---|---|
Fast |
reader | The stream to read the value from |
bool | keepDirtyDelta | Whether or not the container should keep the dirty delta, or mark the delta as consumed |
Overrides
ReadField(FastBufferReader)
Reads the complete state from the reader and applies it
Declaration
public override void ReadField(FastBufferReader reader)
Parameters
Type | Name | Description |
---|---|---|
Fast |
reader | The stream to read the state from |
Overrides
ResetDirty()
Resets the dirty state and marks the variable as synced / clean
Declaration
public override void ResetDirty()
Overrides
WriteDelta(FastBufferWriter)
Writes the variable to the writer
Declaration
public override void WriteDelta(FastBufferWriter writer)
Parameters
Type | Name | Description |
---|---|---|
Fast |
writer | The stream to write the value to |
Overrides
WriteField(FastBufferWriter)
Writes the complete state of the variable to the writer
Declaration
public override void WriteField(FastBufferWriter writer)
Parameters
Type | Name | Description |
---|---|---|
Fast |
writer | The stream to write the state to |