Skip to content
0.2.0-dev Download ZIP
147 lines ·9.0 KB Raw
1<?xml version="1.0" encoding="UTF-8" ?>
2<class name="MultiplayerAPI" inherits="RefCounted" api_type="core" keywords="network" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
3 <brief_description>
4 High-level multiplayer API interface.
5 </brief_description>
6 <description>
7 Base class for high-level multiplayer API implementations. See also [MultiplayerPeer].
8 By default, [SceneTree] has a reference to an implementation of this class and uses it to provide multiplayer capabilities (i.e. RPCs) across the whole scene.
9 It is possible to override the MultiplayerAPI instance used by specific tree branches by calling the [method SceneTree.set_multiplayer] method, effectively allowing to run both client and server in the same scene.
10 It is also possible to extend or replace the default implementation via scripting or native extensions. See [MultiplayerAPIExtension] for details about extensions, [SceneMultiplayer] for the details about the default implementation.
11 </description>
12 <tutorials>
13 </tutorials>
14 <methods>
15 <method name="create_default_interface" qualifiers="static">
16 <return type="MultiplayerAPI" />
17 <description>
18 Returns a new instance of the default MultiplayerAPI.
19 </description>
20 </method>
21 <method name="get_default_interface" qualifiers="static">
22 <return type="StringName" />
23 <description>
24 Returns the default MultiplayerAPI implementation class name. This is usually [code]"SceneMultiplayer"[/code] when [SceneMultiplayer] is available. See [method set_default_interface].
25 </description>
26 </method>
27 <method name="get_peers">
28 <return type="PackedInt32Array" />
29 <description>
30 Returns the peer IDs of all connected peers of this MultiplayerAPI's [member multiplayer_peer].
31 </description>
32 </method>
33 <method name="get_remote_sender_id">
34 <return type="int" />
35 <description>
36 Returns the sender's peer ID for the RPC currently being executed.
37 [b]Note:[/b] This method returns [code]0[/code] 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 [code]await[/code] keyword).
38 </description>
39 </method>
40 <method name="get_unique_id">
41 <return type="int" />
42 <description>
43 Returns the unique peer ID of this MultiplayerAPI's [member multiplayer_peer].
44 </description>
45 </method>
46 <method name="has_multiplayer_peer">
47 <return type="bool" />
48 <description>
49 Returns [code]true[/code] if there is a [member multiplayer_peer] set.
50 </description>
51 </method>
52 <method name="is_server">
53 <return type="bool" />
54 <description>
55 Returns [code]true[/code] if this MultiplayerAPI's [member multiplayer_peer] is valid and in server mode (listening for connections).
56 </description>
57 </method>
58 <method name="object_configuration_add">
59 <return type="int" enum="Error" />
60 <param index="0" name="object" type="Object" />
61 <param index="1" name="configuration" type="Variant" />
62 <description>
63 Notifies the MultiplayerAPI of a new [param configuration] for the given [param object]. This method is used internally by [SceneTree] to configure the root path for this MultiplayerAPI (passing [code]null[/code] and a valid [NodePath] as [param configuration]). This method can be further used by MultiplayerAPI implementations to provide additional features, refer to specific implementation (e.g. [SceneMultiplayer]) for details on how they use it.
64 [b]Note:[/b] This method is mostly relevant when extending or overriding the MultiplayerAPI behavior via [MultiplayerAPIExtension].
65 </description>
66 </method>
67 <method name="object_configuration_remove">
68 <return type="int" enum="Error" />
69 <param index="0" name="object" type="Object" />
70 <param index="1" name="configuration" type="Variant" />
71 <description>
72 Notifies the MultiplayerAPI to remove a [param configuration] for the given [param object]. This method is used internally by [SceneTree] to configure the root path for this MultiplayerAPI (passing [code]null[/code] and an empty [NodePath] as [param configuration]). This method can be further used by MultiplayerAPI implementations to provide additional features, refer to specific implementation (e.g. [SceneMultiplayer]) for details on how they use it.
73 [b]Note:[/b] This method is mostly relevant when extending or overriding the MultiplayerAPI behavior via [MultiplayerAPIExtension].
74 </description>
75 </method>
76 <method name="poll">
77 <return type="int" enum="Error" />
78 <description>
79 Method used for polling the MultiplayerAPI. You only need to worry about this if you set [member SceneTree.multiplayer_poll] to [code]false[/code]. By default, [SceneTree] will poll its MultiplayerAPI(s) for you.
80 [b]Note:[/b] This method results in RPCs being called, so they will be executed in the same context of this function (e.g. [code]_process[/code], [code]physics[/code], [Thread]).
81 </description>
82 </method>
83 <method name="rpc">
84 <return type="int" enum="Error" />
85 <param index="0" name="peer" type="int" />
86 <param index="1" name="object" type="Object" />
87 <param index="2" name="method" type="StringName" />
88 <param index="3" name="arguments" type="Array" default="[]" />
89 <description>
90 Sends an RPC to the target [param peer]. The given [param method] will be called on the remote [param object] with the provided [param arguments]. The RPC may also be called locally depending on the implementation and RPC configuration. See [method Node.rpc] and [method Node.rpc_config].
91 [b]Note:[/b] Prefer using [method Node.rpc], [method Node.rpc_id], or [code]my_method.rpc(peer, arg1, arg2, ...)[/code] (in GDScript), since they are faster. This method is mostly useful in conjunction with [MultiplayerAPIExtension] when extending or replacing the multiplayer capabilities.
92 </description>
93 </method>
94 <method name="set_default_interface" qualifiers="static">
95 <return type="void" />
96 <param index="0" name="interface_name" type="StringName" />
97 <description>
98 Sets the default MultiplayerAPI implementation class. This method can be used by modules and extensions to configure which implementation will be used by [SceneTree] when the engine starts.
99 </description>
100 </method>
101 </methods>
102 <members>
103 <member name="multiplayer_peer" type="MultiplayerPeer" setter="set_multiplayer_peer" getter="get_multiplayer_peer">
104 The peer object to handle the RPC system (effectively enabling networking when set). Depending on the peer itself, the MultiplayerAPI will become a network server (check with [method is_server]) and will set root node's network mode to authority, or it will become a regular client peer. All child nodes are set to inherit the network mode by default. Handling of networking-related events (connection, disconnection, new clients) is done by connecting to MultiplayerAPI's signals.
105 </member>
106 </members>
107 <signals>
108 <signal name="connected_to_server">
109 <description>
110 Emitted when this MultiplayerAPI's [member multiplayer_peer] successfully connected to a server. Only emitted on clients.
111 </description>
112 </signal>
113 <signal name="connection_failed">
114 <description>
115 Emitted when this MultiplayerAPI's [member multiplayer_peer] fails to establish a connection to a server. Only emitted on clients.
116 </description>
117 </signal>
118 <signal name="peer_connected">
119 <param index="0" name="id" type="int" />
120 <description>
121 Emitted when this MultiplayerAPI's [member multiplayer_peer] connects with a new peer. ID is the peer ID of the new peer. Clients get notified when other clients connect to the same server. Upon connecting to a server, a client also receives this signal for the server (with ID being 1).
122 </description>
123 </signal>
124 <signal name="peer_disconnected">
125 <param index="0" name="id" type="int" />
126 <description>
127 Emitted when this MultiplayerAPI's [member multiplayer_peer] disconnects from a peer. Clients get notified when other clients disconnect from the same server.
128 </description>
129 </signal>
130 <signal name="server_disconnected">
131 <description>
132 Emitted when this MultiplayerAPI's [member multiplayer_peer] disconnects from server. Only emitted on clients.
133 </description>
134 </signal>
135 </signals>
136 <constants>
137 <constant name="RPC_MODE_DISABLED" value="0" enum="RPCMode">
138 Used with [method Node.rpc_config] to disable a method or property for all RPC calls, making it unavailable. Default for all methods.
139 </constant>
140 <constant name="RPC_MODE_ANY_PEER" value="1" enum="RPCMode">
141 Used with [method Node.rpc_config] to set a method to be callable remotely by any peer. Analogous to the [code]@rpc("any_peer")[/code] annotation. Calls are accepted from all remote peers, no matter if they are node's authority or not.
142 </constant>
143 <constant name="RPC_MODE_AUTHORITY" value="2" enum="RPCMode">
144 Used with [method Node.rpc_config] to set a method to be callable remotely only by the current multiplayer authority (which is the server by default). Analogous to the [code]@rpc("authority")[/code] annotation. See [method Node.set_multiplayer_authority].
145 </constant>
146 </constants>
147</class>