Table of Contents

Class NetworkSandbox

Namespace
Netick.Unity
Assembly
Netick.Unity.dll
public class NetworkSandbox : MonoBehaviour, IGameEngine
Inheritance
Object
Component
Behaviour
MonoBehaviour
NetworkSandbox
Implements
Inherited Members
MonoBehaviour.IsInvoking()
MonoBehaviour.CancelInvoke()
MonoBehaviour.StopCoroutine(Coroutine)
MonoBehaviour.StopAllCoroutines()
MonoBehaviour.destroyCancellationToken
MonoBehaviour.useGUILayout
MonoBehaviour.runInEditMode
Behaviour.enabled
Behaviour.isActiveAndEnabled
Component.GetComponent<T>()
Component.TryGetComponent<T>(out T)
Component.GetComponentInChildren<T>()
Component.GetComponentsInChildren<T>()
Component.GetComponentInParent<T>()
Component.GetComponentsInParent<T>()
Component.GetComponents<T>()
Component.transform
Component.gameObject
Component.tag
Object.GetInstanceID()
Object.GetHashCode()
Object.Instantiate(Object, Vector3, Quaternion)
Object.Instantiate(Object, Vector3, Quaternion, Transform)
Object.Instantiate(Object)
Object.Instantiate(Object, Transform)
Object.Instantiate<T>(T)
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.ToString()
Object.name
Object.hideFlags
Extension Methods

Constructors

NetworkSandbox()

public NetworkSandbox()

Properties

AuthoritativeTick

Last received tick on the client. On the server, it returns the same value as Sandbox.Tick.

public Tick AuthoritativeTick { get; }

Property Value

Tick

Config

Configuration data for Netick.

public NetickConfig Config { get; }

Property Value

NetickConfig

ConnectedClients

A list containing all connected clients currently.

Note: if you want the clients + the server, use ConnectedPlayers.

public IReadOnlyList<ServerConnection> ConnectedClients { get; }

Property Value

IReadOnlyList<ServerConnection>

ConnectedPlayers

A list containing all connected clients currently, in addition to the server (when started as a host).

Note: if you only want the clients, use ConnectedClients.

public IReadOnlyList<NetworkPlayer> ConnectedPlayers { get; }

Property Value

IReadOnlyList<NetworkPlayer>

ConnectedServer

The server the client is connected to.

public NetworkConnection ConnectedServer { get; }

Property Value

NetworkConnection

CurrentRpcCaller

public NetworkPlayer CurrentRpcCaller { get; }

Property Value

NetworkPlayer

CurrentRpcSource

Always always returns null except when called inside the body of an RPC method, it returns the NetworkConnection we are executing RPCs from.

public NetworkConnection CurrentRpcSource { get; }

Property Value

NetworkConnection

DeltaTime

public float DeltaTime { get; }

Property Value

float

Engine

public NetickEngine Engine { get; }

Property Value

NetickEngine

Events

public NetickCallbacks Events { get; }

Property Value

NetickCallbacks

FixedDeltaTime

Time period between network simulation steps. Same as UnityEngine.Time.fixedDeltaTime

public float FixedDeltaTime { get; }

Property Value

float

InKBps

Incoming data in kilobytes per second (KBps).

public float InKBps { get; }

Property Value

float

InPacketLoss

[Client Only] Estimation of incoming packets that are being lost. Value ranges between 0.0 and 1.0, with 1.0 meaning all packets are being lost.

public float InPacketLoss { get; }

Property Value

float

InputEnabled

public bool InputEnabled { get; set; }

Property Value

bool

InterestManagement

public InterestManagement InterestManagement { get; }

Property Value

InterestManagement

InterpolationDelay

[Client Only] Interpolation delay in seconds.

public float InterpolationDelay { get; }

Property Value

float

IsClient

Returns true if this NetworkSandbox is a client.

public bool IsClient { get; }

Property Value

bool

IsConnected

[Client Only] Returns true if this client is currently connected to a server.

public bool IsConnected { get; }

Property Value

bool

IsHost

Returns true if this NetworkSandbox is a host.

public bool IsHost { get; }

Property Value

bool

IsResimulating

Returns true if we are currently resimulating a previous input/tick of the past. On the server, it always returns false since only the clients resimulate.

public bool IsResimulating { get; }

Property Value

bool

IsRunning

Returns true if this NetworkSandbox has been started.

public bool IsRunning { get; }

Property Value

bool

IsServer

Returns true if this NetworkSandbox is the server.

public bool IsServer { get; }

Property Value

bool

IsVisible

public bool IsVisible { get; set; }

Property Value

bool

LocalInterpolation

public LocalInterpolation LocalInterpolation { get; }

Property Value

LocalInterpolation

LocalPlayer

This player.

public NetworkPlayer LocalPlayer { get; }

Property Value

NetworkPlayer

MainSceneBuildIndex

public int MainSceneBuildIndex { get; }

Property Value

int

Monitor

public Monitor Monitor { get; }

Property Value

Monitor

Name

public string Name { get; }

Property Value

string

NetworkTime

public float NetworkTime { get; }

Property Value

float

Objects

A dictionary containing all simulated/registered network objects [NetworkObject] currently.

public IReadOnlyDictionary<int, NetworkObject> Objects { get; }

Property Value

IReadOnlyDictionary<int, NetworkObject>

OutKBps

Outgoing data in kilobytes per second (KBps).

public float OutKBps { get; }

Property Value

float

OutPacketLoss

[Client Only] Estimation of outgoing packets that are being lost. Value ranges between 0.0 and 1.0, with 1.0 meaning all packets are being lost.

public float OutPacketLoss { get; }

Property Value

float

Physics

The UnityEngine.PhysicsScene associated with this NetworkSandbox. Always use this to perform physics queries inside the sandbox instead of UnityEngine.Physics.

public PhysicsScene Physics { get; }

Property Value

PhysicsScene

Physics2D

The UnityEngine.PhysicsScene2D associated with this NetworkSandbox. Always use this to perform physics queries inside the sandbox instead of UnityEngine.Physics2D.

public PhysicsScene2D Physics2D { get; }

Property Value

PhysicsScene2D

PhysicsPrediction

Use this to enable/disable Physics Prediction in the client at runtime.

public bool PhysicsPrediction { get; set; }

Property Value

bool

PostNetworkFixedUpdate

Called after all NetworkFixedUpdate methods have been executed.

Note: it's called with every resimulation on the client.

public Action PostNetworkFixedUpdate { get; set; }

Property Value

Action

PreNetworkFixedUpdate

Called before any NetworkFixedUpdate method have been executed.

Note: it's called with every resimulation on the client.

public Action PreNetworkFixedUpdate { get; set; }

Property Value

Action

PredictedTick

Last predicted tick.

On the client, it always returns the predicted tick of the client, regardless of whether it's a resimulation or not.

On the server, it returns the same value as Sandbox.Tick

public Tick PredictedTick { get; }

Property Value

Tick

RTT

[Client Only] The round-trip time (RTT) of the client in seconds.

public double RTT { get; }

Property Value

double

RemoteInterpolation

public RemoteInterpolation RemoteInterpolation { get; }

Property Value

RemoteInterpolation

ResimulationStep

public int ResimulationStep { get; }

Property Value

int

Resimulations

public int Resimulations { get; }

Property Value

int

ScaledFixedDeltaTime

public float ScaledFixedDeltaTime { get; }

Property Value

float

Scene

The UnityEngine.SceneManagement.Scene associated with this NetworkSandbox.

public Scene Scene { get; }

Property Value

Scene

ServerEndPoint

[Client Only] The IPEndPoint of the server you are connected to. Returns null if you are not connected to any server, or if you are the server.

public IEndPoint ServerEndPoint { get; }

Property Value

IEndPoint

StartMode

public StartMode StartMode { get; }

Property Value

StartMode

Tick

Current simulation tick.

On the server, it's always going forward/increasing.

On the client, during resimulations it returns the current resimulated tick. To check for resimulations, use IsResimulating.

public Tick Tick { get; }

Property Value

Tick

Timer

public SimulationClock Timer { get; }

Property Value

SimulationClock

Transport

The underlying transport used for low-level networking.

public NetworkTransport Transport { get; }

Property Value

NetworkTransport

UserObject

Use this to associate an object with this sandbox.

public object UserObject { get; set; }

Property Value

object

Methods

AttachBehaviour(NetickBehaviour)

Attachs a NetickBehaviour to the simulation.

public void AttachBehaviour(NetickBehaviour behaviour)

Parameters

behaviour NetickBehaviour

AttachNonNetworkedRigidbody(GameObject)

public void AttachNonNetworkedRigidbody(GameObject rigidbodyGameObject)

Parameters

rigidbodyGameObject GameObject

Connect(int, string, byte[], int)

[Client Only] Connects to a remote server.

Note: if you are already connected to a server, and you want to connect to a different one, you have to disconnect before calling this. Otherwise this method does nothing.

Note: connectionData array length should not be more than 300 if you are using Netick Transport.

public void Connect(int port, string ip, byte[] connectionData = null, int connectionDataLength = 0)

Parameters

port int

Port of the server.

ip string

IP address of the server.

connectionData byte[]

RawValue sent with the connection request. Could be used to decide whether or not to allow the connection.

connectionDataLength int

CreateMatch(string)

[Server Only] Creates a match. Only functional if the low-level transport has support for matchmaking.

public void CreateMatch(string name)

Parameters

name string

Name of the match.

DeattachBehaviour(NetickBehaviour)

Deattachs a NetickBehaviour from the simulation.

public void DeattachBehaviour(NetickBehaviour behaviour)

Parameters

behaviour NetickBehaviour

DeattachNonNetworkedRigidbody(GameObject)

public void DeattachNonNetworkedRigidbody(GameObject rigidbodyGameObject)

Parameters

rigidbodyGameObject GameObject

Destroy(NetworkObject)

[Server Only] Destroys a network object.

Note: never call this on a child NetworkObject of the original prefab, only the root of the prefab.

public void Destroy(NetworkObject obj)

Parameters

obj NetworkObject

The object to destroy.

DestroyPool(GameObject)

public void DestroyPool(GameObject networkedPrefab)

Parameters

networkedPrefab GameObject

DisableComponent(Component)

public void DisableComponent(Component component)

Parameters

component Component

DisconnectFromServer()

[Client Only] Disconnects this client from the server.

public void DisconnectFromServer()

EnableComponent(Component)

public void EnableComponent(Component component)

Parameters

component Component

FindGameObjectWithTag(string, bool)

public GameObject FindGameObjectWithTag(string tag, bool activeOnly = true)

Parameters

tag string
activeOnly bool

Returns

GameObject

FindGameObjectsWithTag(string, bool)

public List<GameObject> FindGameObjectsWithTag(string tag, bool activeOnly = true)

Parameters

tag string
activeOnly bool

Returns

List<GameObject>

FindGameObjectsWithTag(string, List<GameObject>, bool)

public List<GameObject> FindGameObjectsWithTag(string tag, List<GameObject> results, bool activeOnly = true)

Parameters

tag string
results List<GameObject>
activeOnly bool

Returns

List<GameObject>

FindObjectOfType<T>(bool)

public T FindObjectOfType<T>(bool activeOnly = true) where T : class

Parameters

activeOnly bool

Returns

T

Type Parameters

T

FindObjectsOfType<T>(bool)

public List<T> FindObjectsOfType<T>(bool activeOnly = true) where T : class

Parameters

activeOnly bool

Returns

List<T>

Type Parameters

T

FindObjectsOfType<T>(List<T>, bool)

public void FindObjectsOfType<T>(List<T> results, bool activeOnly = true) where T : class

Parameters

results List<T>
activeOnly bool

Type Parameters

T

GetBehaviour<T>(NetworkBehaviourRef<T>)

public T GetBehaviour<T>(NetworkBehaviourRef<T> networkBehaviourRef) where T : NetworkBehaviour

Parameters

networkBehaviourRef NetworkBehaviourRef<T>

Returns

T

Type Parameters

T

GetInput<T>(int)

Gets a specific input for the next tick.

public T GetInput<T>(int index = 0) where T : unmanaged

Parameters

index int

Returns

T

Type Parameters

T

GetObject(NetworkObjectRef)

public NetworkObject GetObject(NetworkObjectRef networkObjectRef)

Parameters

networkObjectRef NetworkObjectRef

Returns

NetworkObject

GetObject(int)

Gets the NetworkObject with the specified id. Returns null in case no object with that id exists.

public NetworkObject GetObject(int id)

Parameters

id int

The id of the NetworkObject

Returns

NetworkObject

GetPrefab(string)

Gets a Network Prefab by name.

Note: this causes GC.

public GameObject GetPrefab(string name)

Parameters

name string

Returns

GameObject

The Network Prefab

Hide()

protected void Hide()

InitializePool(GameObject, int, bool)

Initializes the pool for the specified prefab. After this method has been called for a certain prefab, all instances of that prefab will be recycled and reset when created/destroyed.

Note: this method should only be called on OnStartup(NetworkSandbox), in other words, just after Netick has been started.

public void InitializePool(GameObject networkedPrefab, int preloadedAmount, bool hideInactiveMembers = false)

Parameters

networkedPrefab GameObject

Prefab to enable pooling for.

preloadedAmount int

How many instances to be preloaded.

hideInactiveMembers bool

Pass true to hide inactive pool members.

Instantiate(GameObject, Vector3, Quaternion)

Instantiates a prefab. This must be called instead of UnityEngine.Object.Instantiate(UnityEngine.Object) or its variations.

Note: this must be called only for non-networked prefabs. If you want to instantiate a network prefab, use NetworkInstantiate(GameObject, Vector3, Quaternion, NetworkPlayer) instead.

public GameObject Instantiate(GameObject prefab, Vector3 position, Quaternion rotation)

Parameters

prefab GameObject

The prefab to be instantiated.

position Vector3

Position of the instantiated object.

rotation Quaternion

Rotation of the instantiated object.

Returns

GameObject

Instantiate<T>(T, Vector3, Quaternion)

public T Instantiate<T>(T prefab, Vector3 position, Quaternion rotation) where T : MonoBehaviour

Parameters

prefab T
position Vector3
rotation Quaternion

Returns

T

Type Parameters

T

Kick(ServerConnection)

[Server Only] Disconnects a client from the server.

public void Kick(ServerConnection client)

Parameters

client ServerConnection

The client to be disconnected.

LoadSceneAsync(int, LoadSceneMode)

public void LoadSceneAsync(int buildIndex, LoadSceneMode loadSceneMode)

Parameters

buildIndex int
loadSceneMode LoadSceneMode

LoadSceneAsync(int, LoadSceneParameters)

public void LoadSceneAsync(int buildIndex, LoadSceneParameters loadSceneParameters)

Parameters

buildIndex int
loadSceneParameters LoadSceneParameters

LoadSceneAsync(string, LoadSceneMode)

[Server Only] Loads a scene asynchronously.

public void LoadSceneAsync(string sceneName, LoadSceneMode loadSceneMode)

Parameters

sceneName string
loadSceneMode LoadSceneMode

LoadSceneAsync(string, LoadSceneParameters)

public void LoadSceneAsync(string sceneName, LoadSceneParameters loadSceneParameters)

Parameters

sceneName string
loadSceneParameters LoadSceneParameters

Log(object)

public void Log(object message)

Parameters

message object

LogError(object)

public void LogError(object message)

Parameters

message object

LogWarning(object)

public void LogWarning(object message)

Parameters

message object

NetworkInstantiate(GameObject, Vector3, Quaternion, NetworkPlayer)

[Server Only] Instantiates a network prefab.

This must only be called on the server, since only the server can instantiate network prefabs.

Note: make sure the prefab has been registered.

Note: the specified input source will be given to every NetworkObject child of this prefab.

public NetworkObject NetworkInstantiate(GameObject prefab, Vector3 position, Quaternion rotation, NetworkPlayer inputSource = null)

Parameters

prefab GameObject

The prefab to be instantiated.

position Vector3

Position of the instantiated object.

rotation Quaternion

Rotation of the instantiated object.

inputSource NetworkPlayer

Input source of the instantiated object.

Returns

NetworkObject

NetworkInstantiate<T>(T, Vector3, Quaternion, NetworkPlayer)

public T NetworkInstantiate<T>(T prefab, Vector3 position, Quaternion rotation, NetworkPlayer inputSource = null) where T : MonoBehaviour

Parameters

prefab T
position Vector3
rotation Quaternion
inputSource NetworkPlayer

Returns

T

Type Parameters

T

RefreshMatchList()

Requests an update to the match list. Only functional if the low-level transport has support for matchmaking.

public void RefreshMatchList()

RemoveFromLoop(NetworkObject)

public void RemoveFromLoop(NetworkObject obj)

Parameters

obj NetworkObject

RestartTimer(float, bool)

public NetworkTimer RestartTimer(float time, bool usePredictedTiming = true)

Parameters

time float
usePredictedTiming bool

Returns

NetworkTimer

SetComponentEnabled(Component, bool)

public void SetComponentEnabled(Component component, bool enabled)

Parameters

component Component
enabled bool

SetInput<T>(T, int)

Sets a specific input for the next tick.

public void SetInput<T>(T input, int index = 0) where T : unmanaged

Parameters

input T
index int

Type Parameters

T

Show()

protected void Show()

StartTimer(float, bool)

public NetworkTimer StartTimer(float time, bool usePredictedTiming = true)

Parameters

time float
usePredictedTiming bool

Returns

NetworkTimer

SwitchScene(int)

[Server Only] Switches to a different scene. This must be called instead of LoadSceneAsync(int) or its variations.

public void SwitchScene(int sceneBuildIndex)

Parameters

sceneBuildIndex int

SceneBuildIndex of the desired scene.

SwitchScene(string)

[Server Only] Switches to a different scene. This must be called instead of LoadSceneAsync(int) or its variations.

public void SwitchScene(string sceneName)

Parameters

sceneName string

TickToTime(Tick)

Converts tick to time in seconds.

public float TickToTime(Tick tick)

Parameters

tick Tick

Returns

float

TickToTime(float)

Converts tick to time in seconds.

public float TickToTime(float tick)

Parameters

tick float

Returns

float

TryGetBehaviour<T>(NetworkBehaviourRef<T>, out T)

public bool TryGetBehaviour<T>(NetworkBehaviourRef<T> networkBehaviourRef, out T behaviour) where T : NetworkBehaviour

Parameters

networkBehaviourRef NetworkBehaviourRef<T>
behaviour T

Returns

bool

Type Parameters

T

TryGetBehaviour<T>(int, out T)

Tries to get the NetworkBehaviour of a NetworkObject with the specified id.

public bool TryGetBehaviour<T>(int id, out T behaviour) where T : NetworkBehaviour

Parameters

id int

The id of the network object

behaviour T

Returns

bool

Type Parameters

T

TryGetObject(NetworkObjectRef, out NetworkObject)

public bool TryGetObject(NetworkObjectRef networkObjectRef, out NetworkObject obj)

Parameters

networkObjectRef NetworkObjectRef
obj NetworkObject

Returns

bool

TryGetObject(int, out NetworkObject)

Tries to get the NetworkObject with the specified id.

public bool TryGetObject(int id, out NetworkObject obj)

Parameters

id int

The id of the NetworkObject

obj NetworkObject

Returns

bool

UnloadSceneAsync(int)

public void UnloadSceneAsync(int buildIndex)

Parameters

buildIndex int

UnloadSceneAsync(string)

[Server Only] Unloads a scene asynchronously.

public void UnloadSceneAsync(string sceneName)

Parameters

sceneName string

UnloadSceneAsync(Scene)

public void UnloadSceneAsync(Scene scene)

Parameters

scene Scene