Class NetworkReplicator
High-level networking replication system for game objects.
Inheritance
Namespace: FlaxEngine.Networking
Assembly: FlaxEngine.CSharp.dll
Syntax
[Unmanaged]
public static class NetworkReplicator : Object
Properties
EnableLog
Enables verbose logging of the networking runtime. Can be used to debug problems of missing RPC invoke or object replication issues.
Declaration
[Unmanaged]
public static bool EnableLog { get; set; }
Property Value
System.Boolean
|
Hierarchy
Gets or sets the network replication hierarchy.
Declaration
[Unmanaged]
public static NetworkReplicationHierarchy Hierarchy { get; set; }
Property Value
NetworkReplicationHierarchy
|
Methods
AddObject(Object, Object)
Adds the object to the network replication system.
Declaration
[Unmanaged]
public static void AddObject(Object obj, Object parent = null)
Parameters
Object
obj
The object to replicate. |
Object
parent
The parent of the object (eg. player that spawned it). |
Remarks
Does nothing if network is offline.
AddRPC(Type, String, NetworkReplicator.ExecuteRPCFunc, Boolean, Boolean, NetworkChannelType)
Registers a RPC method for a given C# method.
Declaration
[Unmanaged]
public static void AddRPC(Type type, string name, NetworkReplicator.ExecuteRPCFunc execute, bool isServer = true, bool isClient = false, NetworkChannelType channel)
Parameters
System.Type
type
The C# type (FlaxEngine.Object). |
System.String
name
The RPC method name (from that type). |
NetworkReplicator.ExecuteRPCFunc
execute
Function to call for RPC execution. |
System.Boolean
isServer
Server RPC. |
System.Boolean
isClient
Client RPC. |
NetworkChannelType
channel
Network channel to use for RPC transport. |
AddSerializer(Type, NetworkReplicator.SerializeFunc, NetworkReplicator.SerializeFunc)
Registers a new serialization methods for a given C# type.
Declaration
[Unmanaged]
public static void AddSerializer(Type type, NetworkReplicator.SerializeFunc serialize, NetworkReplicator.SerializeFunc deserialize)
Parameters
System.Type
type
The C# type (class or structure). |
NetworkReplicator.SerializeFunc
serialize
Function to call for value serialization. |
NetworkReplicator.SerializeFunc
deserialize
Function to call for value deserialization. |
Remarks
Use Object.FromUnmanagedPtr(instancePtr/streamPtr) to get object or NetworkStream from raw native pointers.
BeginInvokeRPC()
Begins invoking the RPC and returns the Network Stream to serialize parameters to.
Declaration
[Unmanaged]
public static NetworkStream BeginInvokeRPC()
Returns
NetworkStream
Network Stream to write RPC parameters to. |
DespawnObject(Object)
Despawns the object from the other clients. Deletes object from remove clients.
Declaration
[Unmanaged]
public static void DespawnObject(Object obj)
Parameters
Object
obj
The object to despawn on other clients. |
Remarks
Does nothing if network is offline.
DirtyObject(Object)
Marks the object dirty to perform immediate replication to the other clients.
Declaration
[Unmanaged]
public static void DirtyObject(Object obj)
Parameters
Object
obj
The network object. |
EndInvokeRPC(Object, Type, String, NetworkStream, UInt32[])
Ends invoking the RPC.
Declaration
[Unmanaged]
public static bool EndInvokeRPC(Object obj, Type type, string name, NetworkStream argsStream, uint[] targetIds = null)
Parameters
Object
obj
The target object to invoke RPC. |
System.Type
type
The RPC type. |
System.String
name
The RPC name. |
NetworkStream
argsStream
The RPC serialized arguments stream returned from BeginInvokeRPC. |
System.UInt32[]
targetIds
Optional list with network client IDs that should receive RPC. Empty to send on all clients. Ignored by Server RPCs. |
Returns
System.Boolean
True if RPC cannot be executed locally, false if execute it locally too (checks RPC mode and target client ids). |
GetObjectOwnerClientId(Object)
Gets the Client Id of the network object owner.
Declaration
[Unmanaged]
public static uint GetObjectOwnerClientId(Object obj)
Parameters
Object
obj
The network object. |
Returns
System.UInt32
The Client Id. |
GetObjectRole(Object)
Gets the role of the network object used locally (eg. to check if can simulate object).
Declaration
[Unmanaged]
public static NetworkObjectRole GetObjectRole(Object obj)
Parameters
Object
obj
The network object. |
Returns
NetworkObjectRole
The object role. |
HasObject(Object)
Checks if the network object is spawned or added to the network replication system.
Declaration
[Unmanaged]
public static bool HasObject(Object obj)
Parameters
Object
obj
The network object. |
Returns
System.Boolean
True if object exists in networking, otherwise false. |
InvokeSerializer(Type, Object, NetworkStream, Boolean)
Invokes the network replication serializer for a given type.
Declaration
[Unmanaged]
public static bool InvokeSerializer(Type type, Object instance, NetworkStream stream, bool serialize)
Parameters
System.Type
type
The scripting type to serialize. |
Object
instance
The value instance to serialize. |
NetworkStream
stream
The input/output stream to use for serialization. |
System.Boolean
serialize
True if serialize, otherwise deserialize mode. |
Returns
System.Boolean
True if failed, otherwise false. |
InvokeSerializer(Type, IntPtr, NetworkStream, Boolean)
Invokes the network replication serializer for a given type.
Declaration
[Unmanaged]
public static bool InvokeSerializer(Type type, IntPtr instance, NetworkStream stream, bool serialize)
Parameters
System.Type
type
The scripting type to serialize. |
System.IntPtr
instance
The value instance to serialize. |
NetworkStream
stream
The input/output stream to use for serialization. |
System.Boolean
serialize
True if serialize, otherwise deserialize mode. |
Returns
System.Boolean
True if failed, otherwise false. |
IsObjectOwned(Object)
Checks if the network object is owned locally (thus current client has authority to manage it).
Declaration
[Unmanaged]
public static bool IsObjectOwned(Object obj)
Parameters
Object
obj
The network object. |
Returns
System.Boolean
True if object is owned by this client, otherwise false. |
Remarks
Equivalent to GetObjectRole == OwnedAuthoritative.
IsObjectReplicated(Object)
Checks if the network object is replicated locally (any local changes might be overriden by other client who owns this object).
Declaration
[Unmanaged]
public static bool IsObjectReplicated(Object obj)
Parameters
Object
obj
The network object. |
Returns
System.Boolean
True if object is simulated on this client, otherwise false. |
Remarks
Equivalent to (GetObjectRole == Replicated or GetObjectRole == ReplicatedAutonomous).
IsObjectSimulated(Object)
Checks if the network object is simulated locally (thus current client has can modify it - changed might be overriden by other client who owns this object).
Declaration
[Unmanaged]
public static bool IsObjectSimulated(Object obj)
Parameters
Object
obj
The network object. |
Returns
System.Boolean
True if object is simulated on this client, otherwise false. |
Remarks
Equivalent to GetObjectRole != Replicated.
MapObjectId(ref Guid)
Maps object ID into server or client ID (depending on the source ID). Leaves source value unchanged if that specific ID is unused.
Declaration
[Unmanaged]
public static void MapObjectId(ref Guid objectId)
Parameters
System.Guid
objectId
The network object identifier to map. Contains result ID once the method completes. |
RemoveObject(Object)
Removes the object from the network replication system.
Declaration
[Unmanaged]
public static void RemoveObject(Object obj)
Parameters
Object
obj
The object to don't replicate. |
Remarks
Does nothing if network is offline.
ResolveForeignObject(Guid)
Resolves foreign Guid into a local ScriptingObject
Declaration
[Unmanaged]
public static Object ResolveForeignObject(Guid objectId)
Parameters
System.Guid
objectId
The Guid of a foreign object. |
Returns
Object
Object if managed to resolve, otherwise null. |
SetObjectOwnership(Object, UInt32, NetworkObjectRole, Boolean)
Sets the network object ownership - owning client identifier and local role to use.
Declaration
[Unmanaged]
public static void SetObjectOwnership(Object obj, uint ownerClientId, NetworkObjectRole localRole, bool hierarchical = true)
Parameters
Object
obj
The network object. |
System.UInt32
ownerClientId
The new owner. Set to NetworkManager.LocalClientId for local client to be owner (server might reject it). |
NetworkObjectRole
localRole
The local role to assign for the object. |
System.Boolean
hierarchical
True if apply the ownership to all child objects of this object (eg. all child actors and scripts attached to the networked actor). |
SpawnObject(Object)
Spawns the object to the other clients. Can be spawned by the owner who locally created it (eg. from prefab).
Declaration
[Unmanaged]
public static void SpawnObject(Object obj)
Parameters
Object
obj
The object to spawn on other clients. |
Remarks
Does nothing if network is offline. Doesn't spawn actor in a level - but in network replication system.
SpawnObject(Object, UInt32[])
Spawns the object to the other clients. Can be spawned by the owner who locally created it (eg. from prefab).
Declaration
[Unmanaged]
public static void SpawnObject(Object obj, uint[] clientIds)
Parameters
Object
obj
The object to spawn on other clients. |
System.UInt32[]
clientIds
List with network client IDs that should receive network spawn event. Empty to spawn on all clients. |
Remarks
Does nothing if network is offline. Doesn't spawn actor in a level - but in network replication system.