Class NetworkSandbox
NetworkSandbox represents a networked game instance in Netick.
public class NetworkSandbox : MonoBehaviour, IGameEngine
- Inheritance
-
NetworkSandbox
- Implements
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
Config
Configuration data for Netick.
public NetickConfig Config { get; }
Property Value
ConnectedClients
A list containing all connected clients currently.
Note: if you want the clients + the server, use ConnectedPlayers.
[Obsolete("This will be removed in the future, please use Players instead.")]
public IReadOnlyList<ServerConnection> ConnectedClients { get; }
Property Value
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.
[Obsolete("This will be removed in the future, please use Players instead.")]
public IReadOnlyList<NetworkPlayer> ConnectedPlayers { get; }
Property Value
ConnectedServer
The server the client is connected to.
public NetworkConnection ConnectedServer { get; }
Property Value
CurrentRpcCaller
Always always returns null except when called inside the body of an RPC method, it returns the NetworkPlayer we are executing RPCs from. Works the same as CurrentRpcSource, except when the RPC is called by the local player, it returns Sandbox.LocalPlayer.
[Obsolete("This will be removed in the future, please read the doc article on Rpcs to learn the new replacement.")]
public NetworkPlayer CurrentRpcCaller { get; }
Property Value
CurrentRpcSource
Always always returns null except when called inside the body of an RPC method, it returns the NetworkConnection we are executing RPCs from.
[Obsolete("This will be removed in the future, please read the doc article on Rpcs to learn the new replacement.")]
public NetworkConnection CurrentRpcSource { get; }
Property Value
DeltaTime
Time period between frames. Same as UnityEngine.Time.deltaTime
public float DeltaTime { get; }
Property Value
Engine
The NetickEngine instance attached to this sandbox.
public NetickEngine Engine { get; }
Property Value
Events
Use this to subscribe/unsubscribe to/from Netick events.
public NetworkCallbacks Events { get; }
Property Value
FixedDeltaTime
Time period between network simulation steps. Same as UnityEngine.Time.fixedDeltaTime
public float FixedDeltaTime { get; }
Property Value
InKBps
Average incoming data in kilobytes per second (KBps).
public float InKBps { get; }
Property Value
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
InputEnabled
Returns true if input is enabled on this sandbox. Use this to enable/disable input at runtime.
public bool InputEnabled { get; set; }
Property Value
InterestManagement
Use this to manage interest groups and area of interest (AoI) layers.
public InterestManagement InterestManagement { get; }
Property Value
InterpolationDelay
[Client Only] Remote Interpolation delay in seconds.
public float InterpolationDelay { get; }
Property Value
IsClient
Returns true if this NetworkSandbox is a client.
public bool IsClient { get; }
Property Value
IsConnected
[Client Only] Returns true if this client is currently connected to a server.
public bool IsConnected { get; }
Property Value
IsFirstNetworkFixedUpdateCall
Returns true if this NetworkFixedUpdate call is the first one executed in this frame. This excludes re-simulations, and it only refers to new/forward ticks.
public bool IsFirstNetworkFixedUpdateCall { get; }
Property Value
IsHost
Returns true if this NetworkSandbox is a host.
public bool IsHost { get; }
Property Value
IsLastNetworkFixedUpdateCall
Returns true if this NetworkFixedUpdate call is the last one executed in this frame. This excludes re-simulations, and it only refers to new/forward ticks.
public bool IsLastNetworkFixedUpdateCall { get; }
Property Value
IsPlayer
Returns true if this NetworkSandbox is a player, which is the case when running as a Client, Host, or in Single-Player mode.
public bool IsPlayer { get; }
Property Value
IsRecording
Returns true if Netick is recording for replay.
public bool IsRecording { get; }
Property Value
IsReplay
Returns true if Netick is running in ReplayClient mode.
public bool IsReplay { get; }
Property Value
IsResimulating
Returns true if we are currently re-simulating 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
IsRunning
Returns true if this NetworkSandbox has been started.
public bool IsRunning { get; }
Property Value
IsServer
Returns true if this NetworkSandbox is the server.
public bool IsServer { get; }
Property Value
IsVisible
Returns true if this sandbox is visible. Use this to enable/disable visibility at runtime.
public bool IsVisible { get; set; }
Property Value
LocalAlpha
Returns the progress of this sandbox between the current and next tick. A value of 0 represents the start of the current tick, and 1 represents the end of the tick (start of the next tick). Same as Alpha.
public float LocalAlpha { get; }
Property Value
LocalInterpolation
The Local (predicted) Interpolation instance used for interpolating local/predicted objects. Includes useful interpolation data, such as the current interpolation alpha, the ticks being interpolated, and the local interpolation time (in seconds).
public LocalInterpolation LocalInterpolation { get; }
Property Value
LocalPlayer
The local player of this sandbox instance.
public NetworkPlayer LocalPlayer { get; }
Property Value
Monitor
Used to track network metrics and statistics.
public Monitor Monitor { get; }
Property Value
Name
Name of this sandbox.
public string Name { get; }
Property Value
NetworkTime
Current (local/predicted) network time in seconds. Same as Time.
public float NetworkTime { get; }
Property Value
Objects
A dictionary containing all simulated/registered network objects [NetworkObject] currently.
public IReadOnlyDictionary<int, NetworkObject> Objects { get; }
Property Value
OutKBps
Average outgoing data in kilobytes per second (KBps).
public float OutKBps { get; }
Property Value
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
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
Players
A list containing the ids of all connected players currently. This list is networked and synced to all clients.
public IReadOnlyList<NetworkPlayerId> Players { get; }
Property Value
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
RTT
[Client Only] The round-trip time (RTT) of the client in seconds.
public double RTT { get; }
Property Value
RemoteInterpolation
The Remote Interpolation instance used for interpolating remote objects on the client. Includes useful interpolation data, such as the current interpolation alpha, the ticks being interpolated, the remote interpolation time (in seconds), and the remote interpolation delay (in seconds).
Note: this is only valid in the client.
public RemoteInterpolation RemoteInterpolation { get; }
Property Value
Replay
Use this to manage the replay system. Returns null when replay is not enabled.
public Replay Replay { get; }
Property Value
ReplayTransport
The underlying transport used for replay.
public IReplayTransport ReplayTransport { get; }
Property Value
ResimulationCount
[Client Only] The number of re-simulations that have been performed in this tick. This is only valid on the client (and during the re-simulation stage), and it returns 0 on the server.
public int ResimulationCount { get; }
Property Value
ResimulationStep
[Client Only] Returns the current re-simulation step we are currently performing, if we are in the re-simulation stage. This is only valid on the client, and it returns 0 on the server.
public int ResimulationStep { get; }
Property Value
Resimulations
[Obsolete("This will be removed in the future, please use ResimulationCount instead.")]
public int Resimulations { get; }
Property Value
ScaledFixedDeltaTime
Scaled time period between network simulation steps. This is the same as UnityEngine.Time.fixedDeltaTime, but multiplied by UnityEngine.Time.timeScale.
public float ScaledFixedDeltaTime { get; }
Property Value
Scene
The UnityEngine.SceneManagement.Scene associated with this NetworkSandbox.
public Scene Scene { get; }
Property Value
- Scene
ServerEndPoint
[Client Only] The IEndPoint 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
StartMode
The mode this sandbox was started in.
public NetickStartMode StartMode { get; }
Property Value
Tick
Current simulation tick.
On the server, it's always going forward/increasing.
On the client, during resimulations it returns the current re-simulated tick. To check for resimulations, use IsResimulating.
public Tick Tick { get; }
Property Value
Timer
The simulation clock used for managing time in the network simulation.
public SimulationClock Timer { get; }
Property Value
Transport
The underlying transport used for low-level networking.
public NetworkTransport Transport { get; }
Property Value
UserObject
Use this to associate an object with this sandbox.
public object UserObject { get; set; }
Property Value
Methods
AttachBehaviour(NetickBehaviour)
Attaches a NetickBehaviour to the simulation.
public void AttachBehaviour(NetickBehaviour behaviour)
Parameters
behaviourNetickBehaviour
AttachGameObject(GameObject)
public void AttachGameObject(GameObject gameObject)
Parameters
gameObjectGameObject
AttachNonNetworkedRigidbody(GameObject)
public void AttachNonNetworkedRigidbody(GameObject rigidbodyGameObject)
Parameters
rigidbodyGameObjectGameObject
AttachNonNetworkedRigidbody(Rigidbody)
public void AttachNonNetworkedRigidbody(Rigidbody rigidbody)
Parameters
rigidbodyRigidbody
Connect(int, string)
[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)
Parameters
Connect(int, string, ArraySegment<byte>)
public void Connect(int port, string ip, ArraySegment<byte> data)
Parameters
portintipstringdataArraySegment<byte>
Connect(int, string, byte[], int)
public void Connect(int port, string ip, byte[] connectionData, int connectionDataLength)
Parameters
ContainsPlayer(NetworkPlayerId)
Checks if a player with the specified NetworkPlayerId exists in the simulation.
public bool ContainsPlayer(NetworkPlayerId playerId)
Parameters
playerIdNetworkPlayerId
Returns
CreateMatch(string)
[Server Only] Creates a match. Only functional if the low-level transport has support for matchmaking.
public void CreateMatch(string name)
Parameters
namestringName of the match.
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
objNetworkObjectThe object to destroy.
DestroyPool(NetworkObject)
public void DestroyPool(NetworkObject networkedPrefab)
Parameters
networkedPrefabNetworkObject
DestroyPool(GameObject)
public void DestroyPool(GameObject networkedPrefab)
Parameters
networkedPrefabGameObject
DetachBehaviour(NetickBehaviour)
Detaches a NetickBehaviour from the simulation.
public void DetachBehaviour(NetickBehaviour behaviour)
Parameters
behaviourNetickBehaviour
DetachGameObject(GameObject)
public void DetachGameObject(GameObject gameObject)
Parameters
gameObjectGameObject
DetachNonNetworkedRigidbody(GameObject)
public void DetachNonNetworkedRigidbody(GameObject rigidbodyGameObject)
Parameters
rigidbodyGameObjectGameObject
DetachNonNetworkedRigidbody(Rigidbody)
public void DetachNonNetworkedRigidbody(Rigidbody rigidbody)
Parameters
rigidbodyRigidbody
DisableComponent(Component)
public void DisableComponent(Component component)
Parameters
componentComponent
DisconnectFromServer()
[Client Only] Disconnects this client from the server.
public void DisconnectFromServer()
EnableComponent(Component)
public void EnableComponent(Component component)
Parameters
componentComponent
FindGameObjectWithTag(string, bool)
public GameObject FindGameObjectWithTag(string tag, bool activeOnly = true)
Parameters
Returns
- GameObject
FindGameObjectsWithTag(string, bool)
public List<GameObject> FindGameObjectsWithTag(string tag, bool activeOnly = true)
Parameters
Returns
- List<GameObject>
FindGameObjectsWithTag(string, List<GameObject>, bool)
public List<GameObject> FindGameObjectsWithTag(string tag, List<GameObject> results, bool activeOnly = true)
Parameters
Returns
- List<GameObject>
FindObjectOfType<T>(bool)
public T FindObjectOfType<T>(bool activeOnly = true) where T : class
Parameters
activeOnlybool
Returns
- T
Type Parameters
T
FindObjectsOfType<T>(bool)
public List<T> FindObjectsOfType<T>(bool activeOnly = true) where T : class
Parameters
activeOnlybool
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
Type Parameters
T
FindPlayerByEndPoint(IEndPoint)
public NetworkPlayer FindPlayerByEndPoint(IEndPoint endPoint)
Parameters
endPointIEndPoint
Returns
FindSandboxOf(GameObject)
Finds the NetworkSandbox instance associated with the specified UnityEngine.GameObject. Returns null if networking is not running or if no matching sandbox is found for the object's scene.
public static NetworkSandbox FindSandboxOf(GameObject go)
Parameters
goGameObjectThe UnityEngine.GameObject to find the sandbox for.
Returns
- NetworkSandbox
The NetworkSandbox associated with the object's scene, or null if not found.
FindSandboxOf(MonoBehaviour)
Finds the NetworkSandbox instance associated with the specified UnityEngine.GameObject. Returns null if networking is not running or if no matching sandbox is found for the object's scene.
public static NetworkSandbox FindSandboxOf(MonoBehaviour monoBehaviour)
Parameters
monoBehaviourMonoBehaviour
Returns
- NetworkSandbox
The NetworkSandbox associated with the object's scene, or null if not found.
GetBehaviour<T>(NetworkBehaviourRef<T>)
public T GetBehaviour<T>(NetworkBehaviourRef<T> networkBehaviourRef) where T : NetworkBehaviour
Parameters
networkBehaviourRefNetworkBehaviourRef<T>
Returns
- T
Type Parameters
T
GetBehavioursOfType<T>()
Gets all network behaviours (or Netick behaviours) in the simulation that have the type of T.
public List<T> GetBehavioursOfType<T>() where T : NetickBehaviour
Returns
- List<T>
Type Parameters
T
GetBehavioursOfType<T>(List<T>)
Gets all network behaviours (or Netick behaviours) in the simulation that have the type of T.
public void GetBehavioursOfType<T>(List<T> result) where T : NetickBehaviour
Parameters
resultList<T>
Type Parameters
T
GetDefaultLoadSceneParameters()
public LoadSceneParameters GetDefaultLoadSceneParameters()
Returns
- LoadSceneParameters
GetDefaultPhysicsMode()
public LocalPhysicsMode GetDefaultPhysicsMode()
Returns
- LocalPhysicsMode
GetInput<T>(int)
Gets a specific input for the next tick.
public T GetInput<T>(int index = 0) where T : unmanaged
Parameters
indexint
Returns
- T
Type Parameters
T
GetLocalPlayerObject()
Gets the the associated NetworkObject (player object) with the local player.
public NetworkObject GetLocalPlayerObject()
Returns
GetLocalPlayerObject<T>()
Gets the the associated script (player object) of type T with the local player.
public T GetLocalPlayerObject<T>() where T : NetickBehaviour
Returns
- T
Type Parameters
T
GetObject(NetworkObjectRef)
public NetworkObject GetObject(NetworkObjectRef networkObjectRef)
Parameters
networkObjectRefNetworkObjectRef
Returns
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
idintThe id of the NetworkObject
Returns
GetPlayerById(NetworkPlayerId)
Retrieves the NetworkPlayer associated with the given NetworkPlayerId.
On the server, this method can return any player by their ID. On the client, it only returns the local player or the server player.
public NetworkPlayer GetPlayerById(NetworkPlayerId playerId)
Parameters
playerIdNetworkPlayerId
Returns
GetPlayerObject(NetworkPlayer)
Gets the the associated NetworkObject (player object) with this player.
public NetworkObject GetPlayerObject(NetworkPlayer player)
Parameters
playerNetworkPlayer
Returns
GetPlayerObject(NetworkPlayerId)
Gets the the associated NetworkObject (player object) with this player.
public NetworkObject GetPlayerObject(NetworkPlayerId id)
Parameters
Returns
GetPlayerObject<T>(NetworkPlayer)
Gets the the associated script (player object) of type T with this player.
public T GetPlayerObject<T>(NetworkPlayer player) where T : NetickBehaviour
Parameters
playerNetworkPlayer
Returns
- T
Type Parameters
T
GetPlayerObject<T>(NetworkPlayerId)
Gets the the associated script (player object) of type T with this player.
public T GetPlayerObject<T>(NetworkPlayerId id) where T : NetickBehaviour
Parameters
Returns
- T
Type Parameters
T
GetPrefab(string)
Gets a Network Prefab by name.
public GameObject GetPrefab(string name)
Parameters
namestring
Returns
- GameObject
The Network Prefab
InitializePool(NetworkObject, 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 be called on OnStartup(NetworkSandbox), in other words, just after Netick has been started.
public void InitializePool(NetworkObject networkedPrefab, int preloadedAmount, bool hideInactiveMembers = false)
Parameters
networkedPrefabNetworkObjectPrefab to enable pooling for.
preloadedAmountintHow many instances to be preloaded.
hideInactiveMembersboolPass true to hide inactive pool members.
InitializePool(GameObject, int, bool)
public void InitializePool(GameObject networkedPrefab, int preloadedAmount, bool hideInactiveMembers = false)
Parameters
Instantiate(GameObject, Vector3, Quaternion)
[Obsolete("This will be removed in the future, please use LocalInstantiate instead.")]
public GameObject Instantiate(GameObject prefab, Vector3 position, Quaternion rotation)
Parameters
prefabGameObjectpositionVector3rotationQuaternion
Returns
- GameObject
Instantiate<T>(T, Vector3, Quaternion)
[Obsolete("This will be removed in the future, please use LocalInstantiate instead.")]
public T Instantiate<T>(T prefab, Vector3 position, Quaternion rotation) where T : MonoBehaviour
Parameters
prefabTpositionVector3rotationQuaternion
Returns
- T
Type Parameters
T
Kick(NetworkPlayer, ReadOnlySpan<byte>)
public void Kick(NetworkPlayer client, ReadOnlySpan<byte> kickData = default)
Parameters
clientNetworkPlayerkickDataReadOnlySpan<byte>
Kick(NetworkPlayerId, ReadOnlySpan<byte>)
[Server Only] Disconnects a client from the server.
public void Kick(NetworkPlayerId client, ReadOnlySpan<byte> kickData = default)
Parameters
clientNetworkPlayerIdThe client to be disconnected.
kickDataReadOnlySpan<byte>
Kick(ServerConnection, ReadOnlySpan<byte>)
public void Kick(ServerConnection client, ReadOnlySpan<byte> kickData = default)
Parameters
clientServerConnectionkickDataReadOnlySpan<byte>
LoadCustomSceneAsync(int, LoadSceneParameters)
public void LoadCustomSceneAsync(int customIndex, LoadSceneParameters loadSceneParameters)
Parameters
customIndexintloadSceneParametersLoadSceneParameters
LoadSceneAsync(int, LoadSceneMode)
public void LoadSceneAsync(int buildIndex, LoadSceneMode loadSceneMode)
Parameters
buildIndexintloadSceneModeLoadSceneMode
LoadSceneAsync(int, LoadSceneParameters)
public void LoadSceneAsync(int buildIndex, LoadSceneParameters loadSceneParameters)
Parameters
buildIndexintloadSceneParametersLoadSceneParameters
LoadSceneAsync(string, LoadSceneMode)
[Server Only] Loads a scene asynchronously. This should only be called for scenes included in the build of the game.
public void LoadSceneAsync(string sceneName, LoadSceneMode loadSceneMode)
Parameters
sceneNamestringloadSceneModeLoadSceneMode
LoadSceneAsync(string, LoadSceneParameters)
public void LoadSceneAsync(string sceneName, LoadSceneParameters loadSceneParameters)
Parameters
sceneNamestringloadSceneParametersLoadSceneParameters
LocalInstantiate(GameObject)
public GameObject LocalInstantiate(GameObject prefab)
Parameters
prefabGameObject
Returns
- GameObject
LocalInstantiate(GameObject, Vector3)
Instantiates a prefab. This must be called instead of UnityEngine.Object.Instantiate(UnityEngine.Object).
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 LocalInstantiate(GameObject prefab, Vector3 position)
Parameters
prefabGameObjectpositionVector3
Returns
- GameObject
LocalInstantiate(GameObject, Vector3, Quaternion)
public GameObject LocalInstantiate(GameObject prefab, Vector3 position, Quaternion rotation)
Parameters
prefabGameObjectpositionVector3rotationQuaternion
Returns
- GameObject
LocalInstantiate<T>(T)
public T LocalInstantiate<T>(T prefab) where T : MonoBehaviour
Parameters
prefabT
Returns
- T
Type Parameters
T
LocalInstantiate<T>(T, Vector3)
public T LocalInstantiate<T>(T prefab, Vector3 position) where T : MonoBehaviour
Parameters
prefabTpositionVector3
Returns
- T
Type Parameters
T
LocalInstantiate<T>(T, Vector3, Quaternion)
public T LocalInstantiate<T>(T prefab, Vector3 position, Quaternion rotation) where T : MonoBehaviour
Parameters
prefabTpositionVector3rotationQuaternion
Returns
- T
Type Parameters
T
Log(object)
public void Log(object message)
Parameters
messageobject
Log(object, Object)
public void Log(object message, Object context)
Parameters
messageobjectcontextObject
LogError(object)
public void LogError(object message)
Parameters
messageobject
LogError(object, Object)
public void LogError(object message, Object context)
Parameters
messageobjectcontextObject
LogWarning(object)
public void LogWarning(object message)
Parameters
messageobject
LogWarning(object, Object)
public void LogWarning(object message, Object context)
Parameters
messageobjectcontextObject
NetworkInstantiate(GameObject, NetworkPlayer)
public NetworkObject NetworkInstantiate(GameObject prefab, NetworkPlayer inputSource = null)
Parameters
prefabGameObjectinputSourceNetworkPlayer
Returns
NetworkInstantiate(GameObject, NetworkPlayerId)
public NetworkObject NetworkInstantiate(GameObject prefab, NetworkPlayerId inputSource)
Parameters
prefabGameObjectinputSourceNetworkPlayerId
Returns
NetworkInstantiate(GameObject, Vector3, NetworkPlayer)
public NetworkObject NetworkInstantiate(GameObject prefab, Vector3 position, NetworkPlayer inputSource = null)
Parameters
prefabGameObjectpositionVector3inputSourceNetworkPlayer
Returns
NetworkInstantiate(GameObject, Vector3, NetworkPlayerId)
public NetworkObject NetworkInstantiate(GameObject prefab, Vector3 position, NetworkPlayerId inputSource)
Parameters
prefabGameObjectpositionVector3inputSourceNetworkPlayerId
Returns
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
prefabGameObjectpositionVector3rotationQuaternioninputSourceNetworkPlayer
Returns
NetworkInstantiate(GameObject, Vector3, Quaternion, NetworkPlayerId)
[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, NetworkPlayerId inputSource)
Parameters
prefabGameObjectpositionVector3rotationQuaternioninputSourceNetworkPlayerId
Returns
NetworkInstantiate<T>(T, NetworkPlayer)
public T NetworkInstantiate<T>(T prefab, NetworkPlayer inputSource = null) where T : MonoBehaviour
Parameters
prefabTinputSourceNetworkPlayer
Returns
- T
Type Parameters
T
NetworkInstantiate<T>(T, NetworkPlayerId)
public T NetworkInstantiate<T>(T prefab, NetworkPlayerId inputSource) where T : MonoBehaviour
Parameters
prefabTinputSourceNetworkPlayerId
Returns
- T
Type Parameters
T
NetworkInstantiate<T>(T, Vector3, NetworkPlayer)
public T NetworkInstantiate<T>(T prefab, Vector3 position, NetworkPlayer inputSource = null) where T : MonoBehaviour
Parameters
prefabTpositionVector3inputSourceNetworkPlayer
Returns
- T
Type Parameters
T
NetworkInstantiate<T>(T, Vector3, NetworkPlayerId)
public T NetworkInstantiate<T>(T prefab, Vector3 position, NetworkPlayerId inputSource) where T : MonoBehaviour
Parameters
prefabTpositionVector3inputSourceNetworkPlayerId
Returns
- T
Type Parameters
T
NetworkInstantiate<T>(T, 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 T NetworkInstantiate<T>(T prefab, Vector3 position, Quaternion rotation, NetworkPlayer inputSource = null) where T : MonoBehaviour
Parameters
prefabTpositionVector3rotationQuaternioninputSourceNetworkPlayer
Returns
- T
Type Parameters
T
NetworkInstantiate<T>(T, Vector3, Quaternion, NetworkPlayerId)
[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 T NetworkInstantiate<T>(T prefab, Vector3 position, Quaternion rotation, NetworkPlayerId inputSource) where T : MonoBehaviour
Parameters
prefabTpositionVector3rotationQuaternioninputSourceNetworkPlayerId
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
objNetworkObject
SetComponentEnabled(Component, bool)
public void SetComponentEnabled(Component component, bool enabled)
Parameters
componentComponentenabledbool
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
inputTindexint
Type Parameters
T
SetPlayerObject(NetworkPlayer, NetworkObject)
public void SetPlayerObject(NetworkPlayer player, NetworkObject obj)
Parameters
playerNetworkPlayerobjNetworkObject
SetPlayerObject(NetworkPlayerId, NetworkObject)
[Server Only] Sets the the associated NetworkObject (player object) with this player.
public void SetPlayerObject(NetworkPlayerId id, NetworkObject obj)
Parameters
idNetworkPlayerIdobjNetworkObject
StartReplayPlayback(string)
[Client Only] Starts replaying. When not passed any address, Netick will automatically use the latest created file in Application.persistentDataPath/replays/gameVersion/.
public void StartReplayPlayback(string replayAddress = "")
Parameters
replayAddressstring
StartReplayRecording(string)
[Server Only] Starts recording replay data. When not passed any address, Netick will use the current date and time for the replay file name, and the file will be stored in Application.persistentDataPath/replays/gameVersion/.
Note: to stop recording, use StopReplayRecording().
public void StartReplayRecording(string replayAddress = null)
Parameters
replayAddressstring
StartTimer(float, bool)
public NetworkTimer StartTimer(float time, bool usePredictedTiming = true)
Parameters
Returns
StopReplayRecording()
Stops the current recording session. Awaiting this method ensures that recording has fully finished.
public Task StopReplayRecording()
Returns
SwitchScene(int)
[Server Only] Switches to a different scene. This must be called instead of UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(int) or its variations. This should only be called for scenes included in the build of the game.
public void SwitchScene(int sceneBuildIndex)
Parameters
sceneBuildIndexintSceneBuildIndex of the desired scene.
SwitchScene(string)
[Server Only] Switches to a different scene. This must be called instead of UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(int) or its variations. This should only be called for scenes included in the build of the game.
public void SwitchScene(string sceneName)
Parameters
sceneNamestring
TickToTime(Tick)
Converts ticks to time in seconds.
public float TickToTime(Tick tick)
Parameters
tickTick
Returns
TickToTime(float)
Converts ticks to time in seconds.
public float TickToTime(float tick)
Parameters
tickfloat
Returns
TimeToTick(float)
Converts time (in seconds) to ticks.
public Tick TimeToTick(float time)
Parameters
timefloat
Returns
TryGetBehaviour<T>(NetworkBehaviourRef<T>, out T)
public bool TryGetBehaviour<T>(NetworkBehaviourRef<T> networkBehaviourRef, out T behaviour) where T : NetworkBehaviour
Parameters
networkBehaviourRefNetworkBehaviourRef<T>behaviourT
Returns
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
idintThe id of the network object
behaviourT
Returns
Type Parameters
T
TryGetConnectionRefusalData(out ArraySegment<byte>)
public bool TryGetConnectionRefusalData(out ArraySegment<byte> data)
Parameters
dataArraySegment<byte>
Returns
TryGetKickData(out ArraySegment<byte>)
public bool TryGetKickData(out ArraySegment<byte> data)
Parameters
dataArraySegment<byte>
Returns
TryGetLocalPlayerObject(out NetworkObject)
Tries to get the the associated NetworkObject (player object) with the local player.
public bool TryGetLocalPlayerObject(out NetworkObject playerObject)
Parameters
playerObjectNetworkObject
Returns
TryGetLocalPlayerObject<T>(out T)
Tries to get the the associated script (player object) of type T with the local player.
public bool TryGetLocalPlayerObject<T>(out T playerObject) where T : NetickBehaviour
Parameters
playerObjectT
Returns
Type Parameters
T
TryGetObject(NetworkObjectRef, out NetworkObject)
public bool TryGetObject(NetworkObjectRef networkObjectRef, out NetworkObject obj)
Parameters
networkObjectRefNetworkObjectRefobjNetworkObject
Returns
TryGetObject(int, out NetworkObject)
Tries to get the NetworkObject with the specified id.
public bool TryGetObject(int id, out NetworkObject obj)
Parameters
idintThe id of the NetworkObject
objNetworkObject
Returns
TryGetPlayerObject(NetworkPlayer, out NetworkObject)
Tries to get the the associated NetworkObject (player object) with this player.
public bool TryGetPlayerObject(NetworkPlayer player, out NetworkObject playerObject)
Parameters
playerNetworkPlayerplayerObjectNetworkObject
Returns
TryGetPlayerObject(NetworkPlayerId, out NetworkObject)
Tries to get the the associated NetworkObject (player object) with this player.
public bool TryGetPlayerObject(NetworkPlayerId id, out NetworkObject playerObject)
Parameters
idNetworkPlayerIdplayerObjectNetworkObject
Returns
TryGetPlayerObject<T>(NetworkPlayer, out T)
Tries to get the the associated script (player object) of type T with this player.
public bool TryGetPlayerObject<T>(NetworkPlayer player, out T playerObject) where T : NetickBehaviour
Parameters
playerNetworkPlayerplayerObjectT
Returns
Type Parameters
T
TryGetPlayerObject<T>(NetworkPlayerId, out T)
Tries to get the the associated script (player object) of type T with this player.
public bool TryGetPlayerObject<T>(NetworkPlayerId id, out T playerObject) where T : NetickBehaviour
Parameters
idNetworkPlayerIdplayerObjectT
Returns
Type Parameters
T
UnloadCustomSceneAsync(int)
public void UnloadCustomSceneAsync(int customIndex)
Parameters
customIndexint
UnloadSceneAsync(int)
public void UnloadSceneAsync(int buildIndex)
Parameters
buildIndexint
UnloadSceneAsync(string)
[Server Only] Unloads a scene asynchronously.
public void UnloadSceneAsync(string sceneName)
Parameters
sceneNamestring
UnloadSceneAsync(Scene)
public void UnloadSceneAsync(Scene scene)
Parameters
sceneScene
Events
PostNetworkFixedUpdate
Called after all NetworkFixedUpdate methods have been executed.
Note: it's called with every resimulation on the client.
public event Action PostNetworkFixedUpdate
Event Type
PostNetworkRender
Called after all NetworkRender methods have been executed.
public event Action PostNetworkRender
Event Type
PostNetworkUpdate
Called after all NetworkUpdate methods have been executed.
public event Action PostNetworkUpdate
Event Type
PreNetworkFixedUpdate
Called before any NetworkFixedUpdate method have been executed.
Note: it's called with every resimulation on the client.
public event Action PreNetworkFixedUpdate
Event Type
PreNetworkRender
Called before any NetworkRender method have been executed.
public event Action PreNetworkRender
Event Type
PreNetworkUpdate
Called before any NetworkUpdate method have been executed.
public event Action PreNetworkUpdate