NetworkObject - RoyasDev/EzNet GitHub Wiki

Introduction

The NetworkObject class manages all of the specific logic for a object that sync across the network. This class is meant to be overridden just like the NetworkManager class. If you are overriding the NetworkObject class you need to call super() in ready to make it function as expected.

The NetworkObject tries to automatically grab reference to the NetworkManager @onready make sure the path is correct in the inspector. It has the /root/ added to the start of the path by default

Exported Variables

network_manager_name # This is the path to the NetworkManager class that is relative to the /root/ 

set_server_to_owner_on_disconnect : bool # If this is set to true the object is set to be owned by the server when a player is disconnected rather than destroyed

Variables

owner_id : int # The id of the network client that owns this object. 1 is the server. Automatically set to the client that requested the spawn of this object. Unless otherwise specified on the server

object_id : int # The unique id of the NetworkObject. If set to -1 it is not initialized

has_initialized : bool # returns false if the NetworkObject has not been initialized

resource_path : String # Is the resource path that the object was spawned from. Will be empty if the object already existed in the scene before the network connection was established

spawn_args : Dictionary # The arguments that this NetworkObject was spawned with

Validators

validate_ownership_change_callable : Callable # takes in the id of who sent the request to take ownership of this NetworkObject. Returns false if they cannot take ownership. If this is unassigned it will be automatically true.

validate_destroy_request_callable : Callable # takes in the id of who sent the request to destroy this NetworkObject. Returns false if they cannot destroy it. If this is unassigned it will be automatically true.

Signals

on_network_ready() # Emitted when the object finishes initializing

on_owner_changed(old_owner : int, new_owner : int) # Emitted when the object changes owners

on_network_destroy() # Emitted when the object is destroyed

Godot Functions

func _ready():
    super() # MUST BE CALLED IN READY IF OVERRIDING THE NETWORK OBJECT

Public Functions

_is_owner() -> bool # return true if this client is the owner

RPC's

_request_ownership() # Called from the client on the server to request ownership on the object

_change_owner(new_owner : int) # Called from the server on the clients when changing the object owner

_request_destroy_network_object() # Called from the client on the server to request to destroy this object

_destroy_network_object() # Called from the server on the clients to destroy this object