Documentation
¶
Overview ¶
Base class for high-level multiplayer API implementations. See also graphics.gd/classdb/MultiplayerPeer.
By default, graphics.gd/classdb/SceneTree has a reference to an implementation of this class and uses it to provide multiplayer capabilities (i.e. RPCs) across the whole scene.
It is possible to override the MultiplayerAPI instance used by specific tree branches by calling the graphics.gd/classdb/SceneTree.Instance.SetMultiplayer method, effectively allowing to run both client and server in the same scene.
It is also possible to extend or replace the default implementation via scripting or native extensions. See graphics.gd/classdb/MultiplayerAPIExtension for details about extensions, graphics.gd/classdb/SceneMultiplayer for the details about the default implementation.
Index ¶
- func GetDefaultInterface() string
- func SetDefaultInterface(interface_name string)
- type Advanced
- type Any
- type Expanded
- type Extension
- type ID
- type Instance
- func (self Instance) AsMultiplayerAPI() Instance
- func (self Instance) AsObject() [1]gd.Object
- func (self Instance) AsRefCounted() [1]gd.RefCounted
- func (self Instance) GetPeers() []int32
- func (self Instance) GetRemoteSenderId() int
- func (self Instance) GetUniqueId() int
- func (self Instance) HasMultiplayerPeer() bool
- func (self Instance) ID() ID
- func (self Instance) IsServer() bool
- func (self Instance) MultiplayerPeer() MultiplayerPeer.Instance
- func (self Instance) ObjectConfigurationAdd(obj Object.Instance, configuration any) error
- func (self Instance) ObjectConfigurationRemove(obj Object.Instance, configuration any) error
- func (self Instance) OnConnectedToServer(cb func(), flags ...Signal.Flags)
- func (self Instance) OnConnectionFailed(cb func(), flags ...Signal.Flags)
- func (self Instance) OnPeerConnected(cb func(id int), flags ...Signal.Flags)
- func (self Instance) OnPeerDisconnected(cb func(id int), flags ...Signal.Flags)
- func (self Instance) OnServerDisconnected(cb func(), flags ...Signal.Flags)
- func (self Instance) Poll() error
- func (self Instance) Rpc(peer int, obj Object.Instance, method string) error
- func (self Instance) SetMultiplayerPeer(value MultiplayerPeer.Instance)
- func (self *Instance) SetObject(obj [1]gd.Object) bool
- func (self Instance) Virtual(name string) reflect.Value
- type RPCMode
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetDefaultInterface ¶
func GetDefaultInterface() string
Returns the default MultiplayerAPI implementation class name. This is usually "SceneMultiplayer" when graphics.gd/classdb/SceneMultiplayer is available. See SetDefaultInterface.
func SetDefaultInterface ¶
func SetDefaultInterface(interface_name string)
Sets the default MultiplayerAPI implementation class. This method can be used by modules and extensions to configure which implementation will be used by graphics.gd/classdb/SceneTree when the engine starts.
Types ¶
type Advanced ¶
type Advanced = class
Advanced exposes a 1:1 low-level instance of the class, undocumented, for those who know what they are doing.
type Expanded ¶
type Expanded [1]gdclass.MultiplayerAPI
func (Expanded) Rpc ¶
Sends an RPC to the target 'peer'. The given 'method' will be called on the remote 'object' with the provided 'arguments'. The RPC may also be called locally depending on the implementation and RPC configuration. See graphics.gd/classdb/Node.Instance.Rpc and graphics.gd/classdb/Node.Instance.RpcConfig.
Note: Prefer using graphics.gd/classdb/Node.Instance.Rpc, graphics.gd/classdb/Node.Instance.RpcId, or my_method.rpc(peer, arg1, arg2, ...) (in GDScript), since they are faster. This method is mostly useful in conjunction with graphics.gd/classdb/MultiplayerAPIExtension when extending or replacing the multiplayer capabilities.
type Extension ¶
Extension can be embedded in a new struct to create an extension of this class. T should be the type that is embedding this Extension
func (*Extension[T]) AsMultiplayerAPI ¶
func (*Extension[T]) AsRefCounted ¶
func (self *Extension[T]) AsRefCounted() [1]gd.RefCounted
type ID ¶
ID is a typed object ID (reference) to an instance of this class, use it to store references to objects with unknown lifetimes, as an ID will not panic on use if the underlying object has been destroyed.
type Instance ¶
type Instance [1]gdclass.MultiplayerAPI
Instance of the class with convieniently typed arguments and results.
var Nil Instance
Nil is a nil/null instance of the class. Equivalent to the zero value.
func CreateDefaultInterface ¶
func CreateDefaultInterface() Instance
Returns a new instance of the default MultiplayerAPI.
func (Instance) AsMultiplayerAPI ¶
func (Instance) AsRefCounted ¶
func (self Instance) AsRefCounted() [1]gd.RefCounted
func (Instance) GetPeers ¶
Returns the peer IDs of all connected peers of this MultiplayerAPI's Instance.MultiplayerPeer.
func (Instance) GetRemoteSenderId ¶
Returns the sender's peer ID for the RPC currently being executed.
Note: This method returns 0 when called outside of an RPC. As such, the original peer ID may be lost when code execution is delayed (such as with GDScript's await keyword).
func (Instance) GetUniqueId ¶
Returns the unique peer ID of this MultiplayerAPI's Instance.MultiplayerPeer.
func (Instance) HasMultiplayerPeer ¶
Returns true if there is a Instance.MultiplayerPeer set.
func (Instance) IsServer ¶
Returns true if this MultiplayerAPI's Instance.MultiplayerPeer is valid and in server mode (listening for connections).
func (Instance) MultiplayerPeer ¶
func (self Instance) MultiplayerPeer() MultiplayerPeer.Instance
func (Instance) ObjectConfigurationAdd ¶
Notifies the MultiplayerAPI of a new 'configuration' for the given 'object'. This method is used internally by graphics.gd/classdb/SceneTree to configure the root path for this MultiplayerAPI (passing null and a valid node path as 'configuration'). This method can be further used by MultiplayerAPI implementations to provide additional features, refer to specific implementation (e.g. graphics.gd/classdb/SceneMultiplayer) for details on how they use it.
Note: This method is mostly relevant when extending or overriding the MultiplayerAPI behavior via graphics.gd/classdb/MultiplayerAPIExtension.
func (Instance) ObjectConfigurationRemove ¶
Notifies the MultiplayerAPI to remove a 'configuration' for the given 'object'. This method is used internally by graphics.gd/classdb/SceneTree to configure the root path for this MultiplayerAPI (passing null and an empty node path as 'configuration'). This method can be further used by MultiplayerAPI implementations to provide additional features, refer to specific implementation (e.g. graphics.gd/classdb/SceneMultiplayer) for details on how they use it.
Note: This method is mostly relevant when extending or overriding the MultiplayerAPI behavior via graphics.gd/classdb/MultiplayerAPIExtension.
func (Instance) OnConnectedToServer ¶
func (Instance) OnConnectionFailed ¶
func (Instance) OnPeerConnected ¶
func (Instance) OnPeerDisconnected ¶
func (Instance) OnServerDisconnected ¶
func (Instance) Poll ¶
Method used for polling the MultiplayerAPI. You only need to worry about this if you set graphics.gd/classdb/SceneTree.Instance.MultiplayerPoll to false. By default, graphics.gd/classdb/SceneTree will poll its MultiplayerAPI(s) for you.
Note: This method results in RPCs being called, so they will be executed in the same context of this function (e.g. _process, physics, graphics.gd/classdb/Thread).
func (Instance) Rpc ¶
Sends an RPC to the target 'peer'. The given 'method' will be called on the remote 'object' with the provided 'arguments'. The RPC may also be called locally depending on the implementation and RPC configuration. See graphics.gd/classdb/Node.Instance.Rpc and graphics.gd/classdb/Node.Instance.RpcConfig.
Note: Prefer using graphics.gd/classdb/Node.Instance.Rpc, graphics.gd/classdb/Node.Instance.RpcId, or my_method.rpc(peer, arg1, arg2, ...) (in GDScript), since they are faster. This method is mostly useful in conjunction with graphics.gd/classdb/MultiplayerAPIExtension when extending or replacing the multiplayer capabilities.
func (Instance) SetMultiplayerPeer ¶
func (self Instance) SetMultiplayerPeer(value MultiplayerPeer.Instance)
type RPCMode ¶
type RPCMode int //gd:MultiplayerAPI.RPCMode
const ( // Used with [graphics.gd/classdb/Node.Instance.RpcConfig] to disable a method or property for all RPC calls, making it unavailable. Default for all methods. RpcModeDisabled RPCMode = 0 // Used with [graphics.gd/classdb/Node.Instance.RpcConfig] to set a method to be callable remotely by any peer. Analogous to the @rpc("any_peer") annotation. Calls are accepted from all remote peers, no matter if they are node's authority or not. RpcModeAnyPeer RPCMode = 1 // Used with [graphics.gd/classdb/Node.Instance.RpcConfig] to set a method to be callable remotely only by the current multiplayer authority (which is the server by default). Analogous to the @rpc("authority") annotation. See [graphics.gd/classdb/Node.Instance.SetMultiplayerAuthority]. RpcModeAuthority RPCMode = 2 )