Table of Contents

Class CoherenceInput

Namespace
Coherence.Toolkit
Assembly
Coherence.Toolkit.dll

This component can be added to a GameObject with CoherenceSync to be able to define which inputs it accepts.

This feature can be used to improve game feel and to prevent cheating by replaying inputs on a simulator or another client. See the coherence docs (section "Input prediction and rollback") for more information.

[NonBindable]
public class CoherenceInput : MonoBehaviour, ICoherenceInput
Inheritance
CoherenceInput
Implements

Constructors

CoherenceInput()

public CoherenceInput()

Fields

DestroyOnInputAuthorityDisconnected

Defines whether the simulator or host that has the state authority over this entity should destroy it when the client with input authority disconnects from the session. Works with server-side simulation.

public bool DestroyOnInputAuthorityDisconnected

Field Value

bool

DisconnectOnTimeReset

Defines whether the client should automatically disconnect in case of unexpected time resync with the server. Works only with the client-side simulation.

public bool DisconnectOnTimeReset

Field Value

bool

InitialBufferSize

public int InitialBufferSize

Field Value

int

InitialInputDelay

public int InitialInputDelay

Field Value

int

MaxInputs

Defines the max number of input fields per CoherenceInput

public const int MaxInputs = 32

Field Value

int

UseFixedSimulationFrames

If true the input system will use the NetworkTime.ClientFixedSimulationFrame (otherwise the NetworkTime.ClientSimulationFrame will be used). When using fixed frames, if deterministic output is desired, it is recommended to update the input driven logic through the OnFixedNetworkUpdate.

public bool UseFixedSimulationFrames

Field Value

bool

internalGetAxis

public Func<string, long?, float> internalGetAxis

Field Value

Func<string, long?, float>

internalGetAxis2D

public Func<string, long?, Vector2> internalGetAxis2D

Field Value

Func<string, long?, Vector2>

internalGetAxis3D

public Func<string, long?, Vector3> internalGetAxis3D

Field Value

Func<string, long?, Vector3>

internalGetButton

public Func<string, long?, bool> internalGetButton

Field Value

Func<string, long?, bool>

internalGetInteger

public Func<string, long?, int> internalGetInteger

Field Value

Func<string, long?, int>

internalGetRotation

public Func<string, long?, Quaternion> internalGetRotation

Field Value

Func<string, long?, Quaternion>

internalGetString

public Func<string, long?, string> internalGetString

Field Value

Func<string, long?, string>

internalOnInputReceived

public Action<IEntityInput, long> internalOnInputReceived

Field Value

Action<IEntityInput, long>

internalRequestBuffer

public Func<IInputBuffer> internalRequestBuffer

Field Value

Func<IInputBuffer>

internalSetAxis

public Action<string, float> internalSetAxis

Field Value

Action<string, float>

internalSetAxis2D

public Action<string, Vector2> internalSetAxis2D

Field Value

Action<string, Vector2>

internalSetAxis3D

public Action<string, Vector3> internalSetAxis3D

Field Value

Action<string, Vector3>

internalSetButton

public Action<string, bool> internalSetButton

Field Value

Action<string, bool>

internalSetInteger

public Action<string, int> internalSetInteger

Field Value

Action<string, int>

internalSetRotation

public Action<string, Quaternion> internalSetRotation

Field Value

Action<string, Quaternion>

internalSetString

public Action<string, string> internalSetString

Field Value

Action<string, string>

Properties

Buffer

Returns an underlying input buffer.

public IInputBuffer Buffer { get; }

Property Value

IInputBuffer

Remarks

For advanced use cases, use with care.

BufferSize

public int BufferSize { get; }

Property Value

int

CurrentSimulationFrame

Current simulation frame as seen by this client. If the UseFixedSimulationFrames is true this returns the ClientFixedSimulationFrame, otherwise the ClientSimulationFrame is returned.

public long CurrentSimulationFrame { get; }

Property Value

long

Delay

public int Delay { get; set; }

Property Value

int

Fields

public CoherenceInput.Field[] Fields { get; }

Property Value

Field[]

InitialBufferDelay

[Obsolete]
[Deprecated("16/02/2023", 1, 0, 0, Reason = "Misspelled InitialInputDelay")]
public int InitialBufferDelay { get; set; }

Property Value

int

IsInputOwner

Determines whether this client is responsible for producing inputs using SetXXX methods.

public bool IsInputOwner { get; }

Property Value

bool

IsProducer

If true, this client is responsible for producing inputs using SetXXX methods.

public bool IsProducer { get; }

Property Value

bool

IsReadyToProcessInputs

Determines whether this input is ready for processing input data. Until this is true, all the inputs set through the SetXXX methods are overwriting each other. Only the last value set will be sent as soon as this property becomes true.

public bool IsReadyToProcessInputs { get; }

Property Value

bool

IsServerSimulated

If true the input system assumes that there's a simulator or host running that processes all inputs sent by the clients while clients merely produce inputs and sync their entities with the host. Authority over this entity will be automatically transferred to the host.

public bool IsServerSimulated { get; }

Property Value

bool

LastAcknowledgedFrame

public long LastAcknowledgedFrame { get; }

Property Value

long

LastConsumedFrame

public long LastConsumedFrame { get; }

Property Value

long

LastFrame

public long LastFrame { get; }

Property Value

long

LastReceivedFrame

public long LastReceivedFrame { get; }

Property Value

long

LastSentFrame

public long LastSentFrame { get; }

Property Value

long

MispredictionFrame

public long? MispredictionFrame { get; }

Property Value

long?

ProcessingEnabled

Determines whether the input processing will happen. If disabled inputs won't be stored in the buffer and won't be sent. Affects only the input-producing side. Defaults to true.

public bool ProcessingEnabled { get; set; }

Property Value

bool

Methods

DebugOnInputReceived(long, object)

[Conditional("COHERENCE_INPUT_DEBUG")]
public void DebugOnInputReceived(long frame, object input)

Parameters

frame long
input object

DebugOnInputSent(long, object)

[Conditional("COHERENCE_INPUT_DEBUG")]
public void DebugOnInputSent(long frame, object input)

Parameters

frame long
input object

GetAxis(string, long?)

Returns a state of the axis as of the given simulation frame.

public float GetAxis(string axisName, long? simulationFrame = null)

Parameters

axisName string

Name of the axis.

simulationFrame long?

Simulation frame for which state is requested. If null the CurrentSimulationFrame will be used.

Returns

float

Value of the axis as of the given simulation frame.

GetAxis2D(string, long?)

Returns a state of the axis2D as of the given simulation frame.

public Vector2 GetAxis2D(string axis2DName, long? simulationFrame = null)

Parameters

axis2DName string

Name of the axis2D.

simulationFrame long?

Simulation frame for which state is requested. If null the CurrentSimulationFrame will be used.

Returns

Vector2

Value of the axis2D as of the given simulation frame.

GetAxis3D(string, long?)

Returns a state of the axis3D as of the given simulation frame.

public Vector3 GetAxis3D(string axis3DName, long? simulationFrame = null)

Parameters

axis3DName string

Name of the axis3D.

simulationFrame long?

Simulation frame for which state is requested. If null the CurrentSimulationFrame will be used.

Returns

Vector3

Value of the axis3D as of the given simulation frame.

GetAxisState(string, long?)

[Obsolete("Please use the 'GetAxis2D' method instead.")]
[Deprecated("15/12/2022", 1, 0, 0, Reason = "Renamed to 'GetAxis2D'")]
public Vector2 GetAxisState(string axisName, long? simulationFrame = null)

Parameters

axisName string
simulationFrame long?

Returns

Vector2

GetButton(string, long?)

Returns a state of the button as of the given simulation frame.

public bool GetButton(string buttonName, long? simulationFrame = null)

Parameters

buttonName string

Name of the button.

simulationFrame long?

Simulation frame for which state is requested. If null the CurrentSimulationFrame will be used.

Returns

bool

Value of the button as of the given simulation frame.

GetButtonRangeState(string, long?)

[Obsolete("Please use the 'GetAxis' method instead.")]
[Deprecated("15/12/2022", 1, 0, 0, Reason = "Renamed to 'GetAxis'")]
public float GetButtonRangeState(string buttonRangeName, long? simulationFrame = null)

Parameters

buttonRangeName string
simulationFrame long?

Returns

float

GetButtonState(string, long?)

[Obsolete("Please use the 'GetButton' method instead.")]
[Deprecated("15/12/2022", 1, 0, 0, Reason = "Renamed to 'GetButton'")]
public bool GetButtonState(string buttonName, long? simulationFrame = null)

Parameters

buttonName string
simulationFrame long?

Returns

bool

GetInteger(string, long?)

Returns a state of the integer as of the given simulation frame.

public int GetInteger(string integerName, long? simulationFrame = null)

Parameters

integerName string

Name of the integer.

simulationFrame long?

Simulation frame for which state is requested. If null the CurrentSimulationFrame will be used.

Returns

int

Value of the integer as of the given simulation frame.

GetRotation(string, long?)

Returns a state of the rotation as of the given simulation frame.

public Quaternion GetRotation(string rotationName, long? simulationFrame = null)

Parameters

rotationName string

Name of the rotation.

simulationFrame long?

Simulation frame for which state is requested. If null the CurrentSimulationFrame will be used.

Returns

Quaternion

Value of the rotation as of the given simulation frame.

GetString(string, long?)

Returns a string state as of the given simulation frame.

public string GetString(string stringName, long? simulationFrame = null)

Parameters

stringName string

Name of the string.

simulationFrame long?

Simulation frame for which state is requested. If null the CurrentSimulationFrame will be used.

Returns

string

Value of the string as of the given simulation frame.

GetStringState(string, long?)

[Obsolete("Please use the 'GetString' method instead.")]
[Deprecated("15/12/2022", 1, 0, 0, Reason = "Renamed to 'GetString'")]
public string GetStringState(string stringName, long? simulationFrame = null)

Parameters

stringName string
simulationFrame long?

Returns

string

SetAxis(string, float)

Sets an axis state for this input. Input is stored as of the CurrentSimulationFrame.

public void SetAxis(string axisName, float value)

Parameters

axisName string

Name of the axis to update.

value float

Value to set.

SetAxis2D(string, Vector2)

Sets an axis2D state for this input. Input is stored as of the CurrentSimulationFrame.

public void SetAxis2D(string axis2DName, Vector2 value)

Parameters

axis2DName string

Name of the axis2D to update.

value Vector2

Value to set.

SetAxis3D(string, Vector3)

Sets an axis3D state for this input. Input is stored as of the CurrentSimulationFrame.

public void SetAxis3D(string axis3DName, Vector3 value)

Parameters

axis3DName string

Name of the axis3D to update.

value Vector3

Value to set.

SetAxisState(string, Vector2)

[Obsolete("Please use the 'SetAxis2D' method instead.")]
[Deprecated("15/12/2022", 1, 0, 0, Reason = "Renamed to 'SetAxis2D'")]
public void SetAxisState(string axisName, Vector2 value)

Parameters

axisName string
value Vector2

SetButton(string, bool)

Sets a button state for this input. Input is stored as of the CurrentSimulationFrame.

public void SetButton(string buttonName, bool value)

Parameters

buttonName string

Name of the button to update.

value bool

Value to set.

SetButtonRangeState(string, float)

[Obsolete("Please use the 'SetAxis' method instead.")]
[Deprecated("15/12/2022", 1, 0, 0, Reason = "Renamed to 'SetAxis'")]
public void SetButtonRangeState(string buttonRangeName, float value)

Parameters

buttonRangeName string
value float

SetButtonState(string, bool)

[Obsolete("Please use the 'SetButton' method instead.")]
[Deprecated("15/12/2022", 1, 0, 0, Reason = "Renamed to 'SetButton'")]
public void SetButtonState(string buttonName, bool value)

Parameters

buttonName string
value bool

SetInteger(string, int)

Sets an integer state for this input. Input is stored as of the CurrentSimulationFrame.

public void SetInteger(string integerName, int value)

Parameters

integerName string

Name of the integer to update.

value int

Value to set.

SetRotation(string, Quaternion)

public void SetRotation(string rotationName, Quaternion value)

Parameters

rotationName string
value Quaternion

SetString(string, string)

Sets a string state for this input. Input is stored as of the CurrentSimulationFrame.

public void SetString(string stringName, string value)

Parameters

stringName string

Name of the string to update.

value string

Value to set.

SetStringState(string, string)

[Obsolete("Please use the 'SetString' method instead.")]
[Deprecated("15/12/2022", 1, 0, 0, Reason = "Renamed to 'SetString'")]
public void SetStringState(string stringName, string value)

Parameters

stringName string
value string

ShouldPause(long)

public bool ShouldPause(long commonReceivedFrame)

Parameters

commonReceivedFrame long

Returns

bool

Update()

protected void Update()

Events

OnStaleInput

public event StaleInputHandler OnStaleInput

Event Type

StaleInputHandler