0 votes

I was following GDQuest's Intro to Multiplayer tutorial (Intro to Multiplayer) and managed to slowly understand little about multiplayer networking. I am making progress but its not without caveots:

I'm having trouble having objects to sync through the network, I managed to get the players to load but problem occurs after I spawn in an object/item that does not exist on the Client Executable:

Sync Error

Error code from clientside if you need clear details:

ERROR: _process_get_node: Failed to get cached path from RPC: Main/Barrel
   At: core/io/multiplayer_api.cpp:266
ERROR: Invalid packet received. Requested node was not found.
   At: core/io/multiplayer_api.cpp:194
ERROR: Node not found: Main/Barrel
   At: scene/main/node.cpp:1382

Would anybody know by any chance how objects can be loaded to the client since it exists on the Master Client?

Would I need to modify the network autoload script to include a function where objects are loaded after the player spawns into the map?

(This is originally GDQuest's Network code from the tutorial, but it helped to get the network executable to work):

extends Node

const DEFAULT_IP = "127.0.0.1"
const DEFAULT_PORT = 31400
const MAX_PLAYERS = 5

var players = { }
var self_data = { name = '', position = Transform(Vector3(1,0,0), Vector3(0,1,0), Vector3(0,0,1), Vector3(0,0,0)) }

signal player_disconnected
signal server_disconnected

func _ready():
    get_tree().connect('network_peer_disconnected', self, '_on_player_disconnected')
    get_tree().connect('network_peer_connected', self, '_on_player_connected')

func create_server(player_nickname):
    self_data.name = player_nickname
    players[1] = self_data
    var peer = NetworkedMultiplayerENet.new()
    peer.create_server(DEFAULT_PORT, MAX_PLAYERS)
    get_tree().set_network_peer(peer)

func connect_to_server(player_nickname):
    self_data.name = player_nickname
    get_tree().connect('connected_to_server', self, '_connected_to_server')
    var peer = NetworkedMultiplayerENet.new()
    peer.create_client(DEFAULT_IP, DEFAULT_PORT)
    get_tree().set_network_peer(peer)

func _connected_to_server():
    var local_player_id = get_tree().get_network_unique_id()
    players[local_player_id] = self_data
    rpc('_send_player_info', local_player_id, self_data)

func _on_player_disconnected(id):
    players.erase(id)

func _on_player_connected(connected_player_id):
    var local_player_id = get_tree().get_network_unique_id()
    if not(get_tree().is_network_server()):
        rpc_id(1, '_request_player_info', local_player_id, connected_player_id)

remote func _request_player_info(request_from_id, player_id):
    if get_tree().is_network_server():
        rpc_id(request_from_id, '_send_player_info', player_id, players[player_id])

# A function to be used if needed. The purpose is to request all players in the current session.
remote func _request_players(request_from_id):
    if get_tree().is_network_server():
        for peer_id in players:
            if( peer_id != request_from_id):
                rpc_id(request_from_id, '_send_player_info', peer_id, players[peer_id])



remote func _send_player_info(id, info):
    players[id] = info
    var new_player = load('res://Main_Player.tscn').instance()
    new_player.name = str(id)
    new_player.set_network_master(id)
    var positioner
    get_node("/root/Main/").add_child(new_player)
    new_player.init(info.name, info.position, true)

func update_position(id, position):
    players[id].position = position

What code is necessary to tell the network server that objects need to be loaded in on the Client Executable?

asked Jul 23 in Engine by Corruptinator (175 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.