Search Results for

    Show / Hide Table of Contents

    Class NetworkReplicator

    High-level networking replication system for game objects.

    Inheritance
    NetworkReplicator
    Assembly: FlaxEngine.dll
    File: Engine/Networking/NetworkReplicator.h
    Syntax
    public class NetworkReplicator

    Fields

    EnableLog

    Enables verbose logging of the networking runtime. Can be used to debug problems of missing RPC invoke or object replication issues.

    Declaration
    public static bool EnableLog
    Field Value
    bool

    Methods

    AddObject(ScriptingObject* obj, const ScriptingObject* parent=nullptr)

    Adds the object to the network replication system.

    Does nothing if network is offline.

    Declaration
    public static void AddObject(ScriptingObject* obj, const ScriptingObject* parent=nullptr)
    Parameters
    ScriptingObject obj

    The object to replicate.

    ScriptingObject parent

    The parent of the object (eg. player that spawned it).

    AddObjectIdMapping(const ScriptingObject* obj, const Guid& objectId)

    Adds a new mapping for object identifier. Can be used to link locally-spawned object with across different clients.

    Declaration
    public static void AddObjectIdMapping(const ScriptingObject* obj, const Guid& objectId)
    Parameters
    ScriptingObject obj

    The network object.

    Guid objectId

    The network object identifier to use (eg. defined by server or global/static).

    AddSerializer(const ScriptingTypeHandle& typeHandle, SerializeFunc serialize, SerializeFunc deserialize, void* serializeTag=nullptr, void* deserializeTag=nullptr)

    Adds the network replication serializer for a given type.

    Declaration
    public static void AddSerializer(const ScriptingTypeHandle& typeHandle, SerializeFunc serialize, SerializeFunc deserialize, void* serializeTag=nullptr, void* deserializeTag=nullptr)
    Parameters
    ScriptingTypeHandle typeHandle

    The scripting type to serialize.

    SerializeFunc serialize

    Serialization callback method.

    SerializeFunc deserialize

    Deserialization callback method.

    void serializeTag

    Serialization callback method tag value.

    void deserializeTag

    Deserialization callback method tag value.

    BeginInvokeRPC()

    Begins invoking the RPC and returns the Network Stream to serialize parameters to.

    Declaration
    public static NetworkStream* BeginInvokeRPC()
    Returns
    NetworkStream

    Network Stream to write RPC parameters to.

    DespawnObject(ScriptingObject* obj)

    Despawns the object from the other clients. Deletes object from remove clients.

    Does nothing if network is offline.

    Declaration
    public static void DespawnObject(ScriptingObject* obj)
    Parameters
    ScriptingObject obj

    The object to despawn on other clients.

    DirtyObject(ScriptingObject* obj)

    Marks the object dirty to perform immediate replication to the other clients.

    Declaration
    public static void DirtyObject(ScriptingObject* obj)
    Parameters
    ScriptingObject obj

    The network object.

    EndInvokeRPC(ScriptingObject* obj, const ScriptingTypeHandle& type, const StringAnsiView& name, NetworkStream* argsStream, Span<uint32> targetIds=Span<uint32>())

    Ends invoking the RPC.

    Declaration
    public static bool EndInvokeRPC(ScriptingObject* obj, const ScriptingTypeHandle& type, const StringAnsiView& name, NetworkStream* argsStream, Span<uint32> targetIds=Span<uint32>())
    Parameters
    ScriptingObject obj

    The target object to invoke RPC.

    ScriptingTypeHandle type

    The RPC type.

    StringAnsiView name

    The RPC name.

    NetworkStream argsStream

    The RPC serialized arguments stream returned from BeginInvokeRPC.

    Span<uint32> targetIds

    Optional list with network client IDs that should receive RPC. Empty to send on all clients. Ignored by Server RPCs.

    Returns
    bool

    True if RPC cannot be executed locally, false if execute it locally too (checks RPC mode and target client ids).

    GetHierarchy()

    Gets the network replication hierarchy.

    Declaration
    public static NetworkReplicationHierarchy* GetHierarchy()
    Returns
    NetworkReplicationHierarchy

    GetObjectOwnerClientId(const ScriptingObject* obj)

    Gets the Client Id of the network object owner.

    Declaration
    public static uint32 GetObjectOwnerClientId(const ScriptingObject* obj)
    Parameters
    ScriptingObject obj

    The network object.

    Returns
    uint32

    The Client Id.

    GetObjectRole(const ScriptingObject* obj)

    Gets the role of the network object used locally (eg. to check if can simulate object).

    Declaration
    public static NetworkObjectRole GetObjectRole(const ScriptingObject* obj)
    Parameters
    ScriptingObject obj

    The network object.

    Returns
    NetworkObjectRole

    The object role.

    HasObject(const ScriptingObject* obj)

    Checks if the network object is spawned or added to the network replication system.

    Declaration
    public static bool HasObject(const ScriptingObject* obj)
    Parameters
    ScriptingObject obj

    The network object.

    Returns
    bool

    True if object exists in networking, otherwise false.

    InvokeSerializer(const ScriptingTypeHandle& typeHandle, void* instance, NetworkStream* stream, bool serialize)

    Invokes the network replication serializer for a given type.

    Declaration
    public static bool InvokeSerializer(const ScriptingTypeHandle& typeHandle, void* instance, NetworkStream* stream, bool serialize)
    Parameters
    ScriptingTypeHandle typeHandle

    The scripting type to serialize.

    void instance

    The value instance to serialize.

    NetworkStream stream

    The input/output stream to use for serialization.

    bool serialize

    True if serialize, otherwise deserialize mode.

    Returns
    bool

    True if failed, otherwise false.

    IsObjectOwned(const ScriptingObject* obj)

    Checks if the network object is owned locally (thus current client has authority to manage it).

    Equivalent to GetObjectRole == OwnedAuthoritative.

    Declaration
    public static bool IsObjectOwned(const ScriptingObject* obj)
    Parameters
    ScriptingObject obj

    The network object.

    Returns
    bool

    True if object is owned by this client, otherwise false.

    IsObjectReplicated(const ScriptingObject* obj)

    Checks if the network object is replicated locally (any local changes might be overriden by other client who owns this object).

    Equivalent to (GetObjectRole == Replicated or GetObjectRole == ReplicatedAutonomous).

    Declaration
    public static bool IsObjectReplicated(const ScriptingObject* obj)
    Parameters
    ScriptingObject obj

    The network object.

    Returns
    bool

    True if object is simulated on this client, otherwise false.

    IsObjectSimulated(const ScriptingObject* obj)

    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).

    Equivalent to GetObjectRole != Replicated.

    Declaration
    public static bool IsObjectSimulated(const ScriptingObject* obj)
    Parameters
    ScriptingObject obj

    The network object.

    Returns
    bool

    True if object is simulated on this client, otherwise false.

    MapObjectId(Guid& objectId)

    Maps object ID into server or client ID (depending on the source ID). Leaves source value unchanged if that specific ID is unused.

    Declaration
    public static void MapObjectId(Guid& objectId)
    Parameters
    Guid objectId

    The network object identifier to map. Contains result ID once the method completes.

    RemoveObject(ScriptingObject* obj)

    Removes the object from the network replication system.

    Does nothing if network is offline.

    Declaration
    public static void RemoveObject(ScriptingObject* obj)
    Parameters
    ScriptingObject obj

    The object to don't replicate.

    ResolveForeignObject(Guid objectId)

    Resolves foreign Guid into a local ScriptingObject

    Declaration
    public static ScriptingObject* ResolveForeignObject(Guid objectId)
    Parameters
    Guid objectId

    The Guid of a foreign object.

    Returns
    ScriptingObject

    Object if managed to resolve, otherwise null.

    SetHierarchy(NetworkReplicationHierarchy* value)

    Sets the network replication hierarchy.

    Declaration
    public static void SetHierarchy(NetworkReplicationHierarchy* value)
    Parameters
    NetworkReplicationHierarchy value

    SetObjectOwnership(ScriptingObject* obj, uint32 ownerClientId, NetworkObjectRole localRole=NetworkObjectRole::Replicated, bool hierarchical=true)

    Sets the network object ownership - owning client identifier and local role to use.

    Declaration
    public static void SetObjectOwnership(ScriptingObject* obj, uint32 ownerClientId, NetworkObjectRole localRole=NetworkObjectRole::Replicated, bool hierarchical=true)
    Parameters
    ScriptingObject obj

    The network object.

    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.

    bool 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(ScriptingObject* obj)

    Spawns the object to the other clients. Can be spawned by the owner who locally created it (eg. from prefab).

    Does nothing if network is offline. Doesn't spawn actor in a level - but in network replication system.

    Declaration
    public static void SpawnObject(ScriptingObject* obj)
    Parameters
    ScriptingObject obj

    The object to spawn on other clients.

    SpawnObject(ScriptingObject* obj, const DataContainer<uint32>& clientIds)

    Spawns the object to the other clients. Can be spawned by the owner who locally created it (eg. from prefab).

    Does nothing if network is offline. Doesn't spawn actor in a level - but in network replication system.

    Declaration
    public static void SpawnObject(ScriptingObject* obj, const DataContainer<uint32>& clientIds)
    Parameters
    ScriptingObject obj

    The object to spawn on other clients.

    DataContainer<uint32> clientIds

    List with network client IDs that should receive network spawn event. Empty to spawn on all clients.

    • Improve this Doc
    • View Source
    In This Article
    Back to top Copyright © 2012-2024 Wojciech Figat