Network Object

NetworkObject Documentation

The NetworkObject class represents a networked object in a Unity scene that can be synchronized over the network. It allows for the creation, ownership, and control of networked objects, as well as the communication of events between networked objects and players.

Namespace

MetaverseCloudEngine.Unity.Networking.Components

Public Methods

  • void AddBehaviour(NetworkObjectBehaviour behaviour): Adds a network behavior to the NetworkObject. Network behaviors are components that react to network events and can be used to implement custom networking logic.

  • void RemoveBehaviour(NetworkObjectBehaviour behaviour): Removes a network behavior from the NetworkObject.

  • void Register(): Registers the NetworkObject with the networking service. This method is typically called automatically when the NetworkObject is spawned.

  • void RequestAuthority(): Requests ownership of the NetworkObject from the server.

  • void RegisterRPC(short procedureID, RpcEventDelegate handler, bool @override = true): Registers a remote procedure call (RPC) handler for the NetworkObject. RPCs are used to communicate events between networked objects and players.

  • void UnregisterRPC(short procedureID, RpcEventDelegate handler): Unregisters an RPC handler from the NetworkObject.

  • void InvokeRPC(short procedureID, int playerID, object content): Invokes an RPC on the NetworkObject and sends it to the specified player.

  • void InvokeRPC(short procedureID, NetworkMessageReceivers receivers, object content, bool buffered = false): Invokes an RPC on the NetworkObject and sends it to the specified receivers.

Public Properties

  • bool TransferAuthorityOnCollide: Whether or not to transfer ownership of the NetworkObject when it collides with another GameObject.

  • IMetaSpaceNetworkingService Networking (read only): The networking service that this NetworkObject is using.

  • int SceneID (read only): The unique identifier of the NetworkObject within the scene.

  • int InputAuthorityID (read only): The unique identifier of the player who owns the NetworkObject.

  • int StateAuthorityID (read only): The unique identifier of the player who is currently controlling the NetworkObject.

  • bool IsStateAuthority (read only): Whether or not the local player is currently controlling the NetworkObject.

  • bool IsInputAuthority (read only): Whether or not the local player is the owner of the NetworkObject.

  • byte Channel (read only): The channel on which this NetworkObject is communicating.

  • bool IsInitialized (read only): Whether or not the NetworkObject has been initialized.

  • bool DestroyWhenCreatorLeave (read only): Whether or not the NetworkObject should be destroyed when the player who created it leaves the scene.

  • int NetworkID (read only): The unique identifier of the NetworkObject within the network.

Usage

  1. To use NetworkObject, start by adding the component to a GameObject in your scene.

  2. You can then add network behaviors to the NetworkObject to implement custom networking logic.

  3. You can also register RPC handlers to allow the NetworkObject to receive and respond to events from other networked objects and players.

  4. To spawn the NetworkObject over the network, you can use the IMetaSpaceNetworkingService.SpawnGameObject() method.

Network Objects in Network Scenarios

Network objects are essential for creating multiplayer experiences in Reach. They allow you to synchronize the state of game objects across multiple clients, ensuring that all players see the same thing.

In a typical network scenario, there is one server and multiple clients. The server is responsible for maintaining the authoritative state of the game world, while the clients are responsible for displaying the game world to the players and sending input to the server.

Network objects are created and spawned on the server. When a client connects to the server, the server sends the client information about all of the network objects that are currently in the scene. The client then creates local instances of these network objects and keeps them synchronized with the server's authoritative state.

Network behaviors can be used to implement custom logic for network objects. For example, a network behavior could be used to handle player input, update the position and rotation of a network object, or trigger events on other network objects.

RPCs are used to communicate events between networked objects and players. For example, an RPC could be used to tell all clients that a player has jumped, or to tell the server that a player has fired a weapon.

For more information on how network objects work in the Metaverse Cloud Engine SDK, please refer to the network architecture documentation.

Last updated