[Net] Basic extensible MultiplayerAPI spawn/despawn.
`PackedScene`s can be configured to be spawnable via a new `MultiplayerAPI.spawnable_config` method. They can be configured either to be spawned automatically when coming from the server or to always require verification. Another method, `MultiplayerAPI.send_spawn` lets you request a spawn on the remote peers. When a peer receive a spawn request: - If it comes from the server and the scene is configured as `SPAWN_MODE_SERVER`: - Spawn the scene (instantiate it, add it to tree). - Emit signal `network_spawn`. - Else: - Emit signal `network_spawn_request`. In a similar way, `despawn`s are handled automatically in `SPAWN_MODE_SERVER`. In `SPAWN_MODE_SERVER`, when a new client connects it will also receive, from the server all the spawned (and not yet despawned) instances.
This commit is contained in:
@@ -116,6 +116,9 @@ void Node::_notification(int p_notification) {
|
||||
memdelete(data.path_cache);
|
||||
data.path_cache = nullptr;
|
||||
}
|
||||
if (data.filename.length()) {
|
||||
get_multiplayer()->scene_enter_exit_notify(data.filename, this, false);
|
||||
}
|
||||
} break;
|
||||
case NOTIFICATION_PATH_CHANGED: {
|
||||
if (data.path_cache) {
|
||||
@@ -147,6 +150,10 @@ void Node::_notification(int p_notification) {
|
||||
|
||||
get_script_instance()->call(SceneStringNames::get_singleton()->_ready);
|
||||
}
|
||||
if (data.filename.length()) {
|
||||
ERR_FAIL_COND(!is_inside_tree());
|
||||
get_multiplayer()->scene_enter_exit_notify(data.filename, this, true);
|
||||
}
|
||||
|
||||
} break;
|
||||
case NOTIFICATION_POSTINITIALIZE: {
|
||||
|
||||
Reference in New Issue
Block a user