Table of Contents

Class CoherenceBridge

Namespace
Coherence.Toolkit
Assembly
Coherence.Toolkit.dll

The CoherenceBridge is the component that all coherence entities use to communicate to the replication server, and other clients. It is also responsible for instantiating and destroying any remote entities that your client should know about.

[NonBindable]
public sealed class CoherenceBridge : CoherenceBehaviour, ICoherenceBridge
Inheritance
CoherenceBridge
Implements

Constructors

CoherenceBridge()

public CoherenceBridge()

Fields

ClientConnectionEntry

The prefab to use when this CoherenceBridge instantiates a client connection.

public CoherenceSyncConfig ClientConnectionEntry

Field Value

CoherenceSyncConfig

SimulatorConnectionEntry

The prefab to use when this CoherenceBridge instantiates a simulator connection.

public CoherenceSyncConfig SimulatorConnectionEntry

Field Value

CoherenceSyncConfig

adjustSimulationFrameByPing

Adjusting the simulation frame by ping accounts for the time required for the packets to travel between the server and the client when calculating the client-server frame drift.

public bool adjustSimulationFrameByPing

Field Value

bool

Remarks

This does not modify the ClientSimulationFrame directly, instead it affects the NetworkTimeScale.

controlTimeScale

Enables automatic client-server synchronization. Can be disabled temporarily for bullet time effects to intentionally desync clients for a short while. When set to true, Time.timeScale is nudged up/down so the game speed adapts to synchronize the game clock with the server clock.

public bool controlTimeScale

Field Value

bool

globalQueryOn

public bool globalQueryOn

Field Value

bool

networkPrefix

public string networkPrefix

Field Value

string

onConnected

Invoked when the CoherenceBridge has successfully connected.

public UnityEvent<CoherenceBridge> onConnected

Field Value

UnityEvent<CoherenceBridge>

onConnectionError

Invoked when the CoherenceBridge experiences a connection error.

public UnityEvent<CoherenceBridge, ConnectionException> onConnectionError

Field Value

UnityEvent<CoherenceBridge, ConnectionException>

onDisconnected

Invoked when the CoherenceBridge has disconnected.

public UnityEvent<CoherenceBridge, ConnectionCloseReason> onDisconnected

Field Value

UnityEvent<CoherenceBridge, ConnectionCloseReason>

onLiveQuerySynced

Invoked when all entities that originated from a CoherenceLiveQuery have been synced.

public UnityEvent<CoherenceBridge> onLiveQuerySynced

Field Value

UnityEvent<CoherenceBridge>

Remarks

This event does not guarantee that all entities will be in the exact state as of the CoherenceLiveQuery creation, it does however guarantee that the entities that were present at the time of query creation have been synced with this client. Eventual consistency rules still apply.

onNetworkEntityCreated

public UnityEvent<CoherenceBridge, NetworkEntityState> onNetworkEntityCreated

Field Value

UnityEvent<CoherenceBridge, NetworkEntityState>

onNetworkEntityDestroyed

public UnityEvent<CoherenceBridge, NetworkEntityState, DestroyReason> onNetworkEntityDestroyed

Field Value

UnityEvent<CoherenceBridge, NetworkEntityState, DestroyReason>

Properties

AuthorityManager

Handles authority requests over entities and adoptions of orphaned entities.

public AuthorityManager AuthorityManager { get; }

Property Value

AuthorityManager

AutoLoginAsGuest

public bool AutoLoginAsGuest { get; }

Property Value

bool

Client

Reference to the IClient of the bridged connection.

public IClient Client { get; }

Property Value

IClient

ClientConnections

Holds information about all CoherenceClientConnections in this session. Can be used to send messages between clients if you're using Connection Prefabs.

public CoherenceClientConnectionManager ClientConnections { get; }

Property Value

CoherenceClientConnectionManager

ClientFixedSimulationFrame

Similar to ClientSimulationFrame but quantized to FixedTimeStep.

public long ClientFixedSimulationFrame { get; }

Property Value

long

ClientID

Unique ClientID of this connection as assigned by the server. If a ClientConnectionPrefab has been assigned, this value can also be accessed using GetMyConnection().ClientId.

public ClientID ClientID { get; }

Property Value

ClientID

CloudService

Service to communicate with the coherence Cloud. You must be logged in with a coherence account, with an Organization and Project selected to be able to use it. Check the coherence Cloud tab in the coherence Hub window for more details.

public CloudService CloudService { get; }

Property Value

CloudService

ConnectionType

The connection type that was used when connecting to the replication server, or Client if no connection attempt has yet been made.

public ConnectionType ConnectionType { get; }

Property Value

ConnectionType

EntitiesManager

Holds information about all entities that are visible to this connection. Both entities you have authority over as well as remote entities.

public EntitiesManager EntitiesManager { get; }

Property Value

EntitiesManager

EntityCount

public int EntityCount { get; }

Property Value

int

FixedUpdateInput

public FixedUpdateInput FixedUpdateInput { get; }

Property Value

FixedUpdateInput

FloatingOriginManager

Contains the API for manipulating with your Floating Origin.

public FloatingOriginManager FloatingOriginManager { get; }

Property Value

FloatingOriginManager

GlobalQueryGameObject

Reference to the GameObject of the global query object.

public GameObject GlobalQueryGameObject { get; set; }

Property Value

GameObject

GlobalQueryOn

public bool GlobalQueryOn { get; set; }

Property Value

bool

InputManager

Handles client entities with server-side input.

public CoherenceInputManager InputManager { get; }

Property Value

CoherenceInputManager

InstantiationScene

Scene where this Bridge will instantiate remote entities. Setting this value will register the bridge to its current scene.

public Scene? InstantiationScene { get; set; }

Property Value

Scene?

IsConnected

public bool IsConnected { get; }

Property Value

bool

IsConnecting

public bool IsConnecting { get; }

Property Value

bool

IsSimulatorOrHost

EXPERIMENTAL - MIGHT CHANGE OR BE REMOVED IN THE NEAR FUTURE

If true this client is considered a host of this session. Any entities with CoherenceInputs, marked as ServerSideWithClientInput, will have their state authority transferred to this client. Any entities marked as ServerSide will remain active on this client.

public bool IsSimulatorOrHost { get; }

Property Value

bool

Remarks

* Always true for Simulator.

* Only the client that created a room can become its host.

Logger

public Logger Logger { get; }

Property Value

Logger

NetStats

public Stats NetStats { get; }

Property Value

Stats

NetworkPrefix

Entities spawned by other clients get this prefix attached to their name.

public string NetworkPrefix { get; }

Property Value

string

NetworkTime

NetworkTime provides access to the network synchronized time and frame state, NetworkTime.

public INetworkTime NetworkTime { get; }

Property Value

INetworkTime

NetworkTimeAsDouble

public double NetworkTimeAsDouble { get; }

Property Value

double

OnAfterFloatingOriginShifted

public Action<FloatingOriginShiftArgs> OnAfterFloatingOriginShifted { get; set; }

Property Value

Action<FloatingOriginShiftArgs>

OnFloatingOriginShifted

Invoked at the end of the floating point origin shifting operation started via SetFloatingOrigin(Vector3d) or TranslateFloatingOrigin(Vector3d), after all objects have been shifted..

public Action<FloatingOriginShiftArgs> OnFloatingOriginShifted { get; set; }

Property Value

Action<FloatingOriginShiftArgs>

Ping

public Ping Ping { get; }

Property Value

Ping

Scene

Reference to the Scene of this bridge.

public Scene Scene { get; }

Property Value

Scene

SceneManager

Contains the API for controlling what scene this client should receive and send updates for.

public CoherenceSceneManager SceneManager { get; set; }

Property Value

CoherenceSceneManager

Transform

public Transform Transform { get; }

Property Value

Transform

UniquenessManager

Holds information about all unique entities in this session. Unique entities are created by setting Uniqueness to No Duplicates in the CoherenceSync component.

public UniquenessManager UniquenessManager { get; }

Property Value

UniquenessManager

WorldPositionMaxRange

Maximum abs position of an entity/liveQuery/floatingOrigin

public static float WorldPositionMaxRange { get; }

Property Value

float

Methods

Connect(EndpointData, ConnectionSettings)

Attempts to connect to the given endpoint using the provided connection settings. The connection type will be determined by IsSimulator.

public void Connect(EndpointData endpoint, ConnectionSettings connectionSettings = null)

Parameters

endpoint EndpointData

The address of the replication server to connect to.

connectionSettings ConnectionSettings

The settings to be used for this connection. If null, Default will be used.

Connect(EndpointData, ConnectionType, ConnectionSettings)

Attempts to connect to the given endpoint using the provided connection type and connection settings.

public void Connect(EndpointData endpoint, ConnectionType connectionType, ConnectionSettings connectionSettings = null)

Parameters

endpoint EndpointData

The address of the replication server to connect to.

connectionType ConnectionType

Used to specify if you are connecting as a client or simulator.

connectionSettings ConnectionSettings

The settings to be used for this connection. If null, Default will be used.

ConnectAsHost(EndpointData, ConnectionSettings)

EXPERIMENTAL - MIGHT CHANGE OR BE REMOVED IN THE NEAR FUTURE

Attempts to connect as a host-client to the given endpoint using the provided connection type and connection settings. Connected client will become a host of the room (see IsSimulatorOrHost).

public void ConnectAsHost(EndpointData endpoint, ConnectionSettings connectionSettings = null)

Parameters

endpoint EndpointData

The address of the replication server to connect to.

connectionSettings ConnectionSettings

The settings to be used for this connection. If null, Default will be used.

Disconnect()

public void Disconnect()

Dispose()

public void Dispose()

DontDestroyOnLoad()

Convenience method for moving making this CoherenceBridge not get destroyed when changing scene.

public void DontDestroyOnLoad()

EntityIdToCoherenceSync(Entity)

Get the CoherenceSync for a Entity.

public CoherenceSync EntityIdToCoherenceSync(Entity from)

Parameters

from Entity

Returns

CoherenceSync

EntityIdToGameObject(Entity)

Get the GameObject for a Entity.

public GameObject EntityIdToGameObject(Entity from)

Parameters

from Entity

Returns

GameObject

EntityIdToRectTransform(Entity)

Get the RectTransform for a Entity.

public RectTransform EntityIdToRectTransform(Entity from)

Parameters

from Entity

Returns

RectTransform

EntityIdToTransform(Entity)

Get the Transform for a Entity.

public Transform EntityIdToTransform(Entity from)

Parameters

from Entity

Returns

Transform

GetClientConnectionEntry()

public CoherenceSyncConfig GetClientConnectionEntry()

Returns

CoherenceSyncConfig

GetCoherenceSyncForEntity(Entity)

Get a CoherenceSync from the mapper.

public ICoherenceSync GetCoherenceSyncForEntity(Entity id)

Parameters

id Entity

A valid Entity (meaning it exists in the mapper)

Returns

ICoherenceSync

GetFloatingOrigin()

Returns the current absolute position of the floating point origin.

public Vector3d GetFloatingOrigin()

Returns

Vector3d

GetNetworkEntityStateForEntity(Entity)

Get a Network Entity State from the mapper.

public NetworkEntityState GetNetworkEntityStateForEntity(Entity id)

Parameters

id Entity

A valid Entity (meaning it exists in the mapper)

Returns

NetworkEntityState

GetSimulatorConnectionEntry()

public CoherenceSyncConfig GetSimulatorConnectionEntry()

Returns

CoherenceSyncConfig

JoinRoom(RoomData)

public void JoinRoom(RoomData room)

Parameters

room RoomData

JoinWorld(WorldData)

public void JoinWorld(WorldData world)

Parameters

world WorldData

OnNetworkEntityCreatedInvoke(NetworkEntityState)

public void OnNetworkEntityCreatedInvoke(NetworkEntityState state)

Parameters

state NetworkEntityState

OnNetworkEntityDestroyedInvoke(NetworkEntityState, DestroyReason)

public void OnNetworkEntityDestroyedInvoke(NetworkEntityState state, DestroyReason destroyReason)

Parameters

state NetworkEntityState
destroyReason DestroyReason

Reconnect()

Attempts to reconnect to the replication server. Then endpoint, connectionSettings and connectionType used with the previous connection attempt will be used again.

public void Reconnect()

SetFloatingOrigin(Vector3d)

Sets the floating point origin absolute position to a new value. Only works if bridge isConnected, otherwise nothing happens.

public bool SetFloatingOrigin(Vector3d newOrigin)

Parameters

newOrigin Vector3d

New floating point origin absolute position

Returns

bool

Returns true if the floating origin was shifted, false if bridge was not connected.

SetInitialScene(uint)

Use this method to set the initial scene to connect to. Setting this value after connecting has no immediate effect (but will effect subsequent reconnect attempts.) To set the scene after connecting, use .

public void SetInitialScene(uint initialScene)

Parameters

initialScene uint

SetRelay(IRelay)

Sets a IRelay to be managed.

public void SetRelay(IRelay newRelay)

Parameters

newRelay IRelay

Remarks

Relay must be set before connecting using a CoherenceBridge. Setting relay during an active connection will keep it disabled and enable it only on the subsequent connection.

SetTransportFactory(ITransportFactory)

Sets the transport factory used when connecting to the replication server. A custom transport factory can be used to tunnel traffic via relay.

public void SetTransportFactory(ITransportFactory transportFactory)

Parameters

transportFactory ITransportFactory

An instance of a transport factory, or null to use the default transport factory.

TranslateFloatingOrigin(Vector3d)

Moves the floating point origin by a translation vector. Only works if bridge isConnected, otherwise nothing happens.

public bool TranslateFloatingOrigin(Vector3d translation)

Parameters

translation Vector3d

Returns

bool

Returns true if the floating origin was shifted, false if bridge was not connected.

TranslateFloatingOrigin(Vector3)

public bool TranslateFloatingOrigin(Vector3 translation)

Parameters

translation Vector3

Returns

bool

UnityObjectToEntityId(CoherenceSync)

Get the Entity for a CoherenceSync.

public Entity UnityObjectToEntityId(CoherenceSync from)

Parameters

from CoherenceSync

Returns

Entity

UnityObjectToEntityId(GameObject)

Get the Entity for a GameObject with CoherenceSync.

public Entity UnityObjectToEntityId(GameObject from)

Parameters

from GameObject

Returns

Entity

UnityObjectToEntityId(Transform)

Get the Entity for a Transform with CoherenceSync.

public Entity UnityObjectToEntityId(Transform from)

Parameters

from Transform

Returns

Entity

Events

OnConnectedInternal

public event Action<ICoherenceBridge> OnConnectedInternal

Event Type

Action<ICoherenceBridge>

OnFixedNetworkUpdate

With MultiClientMode enabled it is recommended to put simulation code in OnFixedNetworkUpdate event handlers instead of FixedUpdate. This allows multiple connected clients within the application to execute at different frequencies for correct network synchronization. The Time.fixedDeltaTime should be applied similar to how it is normally used in FixedUpdate.

public event Action OnFixedNetworkUpdate

Event Type

Action

OnLateFixedNetworkUpdate

Similar to OnFixedNetworkUpdate but guaranteed to be called later.

public event Action OnLateFixedNetworkUpdate

Event Type

Action

OnTimeReset

Triggered the first time SetServerSimulationFrame(AbsoluteSimulationFrame, Ping) is called and at any subsequent call if ClientSimulationFrame and ServerSimulationFrame have drifter too far apart.

public event Action OnTimeReset

Event Type

Action