Godot Version
4.5.1
Question
Hello i’m learning to create a 3D multiplayer game with one headless instance acting like a server and x clients.
Currently i have this code which works :
NetworkManager :
var peer: ENetMultiplayerPeer
var playerName: String = ""
var player_names: Dictionary = {}
signal player_data_received(id)
func host_game(port: int = 9000):
peer = ENetMultiplayerPeer.new()
peer.create_server(port)
multiplayer.multiplayer_peer = peer
print("Hosting on port ", port)
get_tree().change_scene_to_file("res://scenes/Game.tscn")
multiplayer.peer_connected.connect(_on_peer_connected)
multiplayer.peer_disconnected.connect(_on_peer_disconnected)
func join_game(ip: String, port: int = 9000):
peer = ENetMultiplayerPeer.new()
peer.create_client(ip, port)
multiplayer.multiplayer_peer = peer
multiplayer.connected_to_server.connect(_on_connection_success)
func _on_peer_connected(id):
print("Peer connected : ", id)
func _on_peer_disconnected(id):
player_names.erase(id)
print("Peer disconnected : ", id)
func _on_connection_success():
get_tree().change_scene_to_file("res://scenes/Game.tscn")
send_player_info.rpc_id(1, playerName)
@rpc("any_peer", "reliable")
func send_player_info(pseudo: String):
var id = multiplayer.get_remote_sender_id()
#player_names[id] = pseudo
player_data_received.emit(id)
Game.gd :
func _ready():
multiplayer.peer_connected.connect(_on_player_joined)
#NetworkManager.player_data_received2.connect(_on_player_joined)
func _on_player_joined(id):
if multiplayer.is_server():
spawn_player.rpc(id,id,"test")
for existing_id in players.keys():
if existing_id != id:
spawn_player.rpc_id(id, existing_id, existing_id, "test")
but the thing is, when i want to use the signal and modify Game.gd such as : (just uncommenting 3rd line and commenting 2nd line :
func _ready():
#multiplayer.peer_connected.connect(_on_player_joined)
NetworkManager.player_data_received2.connect(_on_player_joined)
then i have a strange bug with this configuration :
Player 1 connect everything is ok
Player 2 connect but can’t see the movement of player 1
Player 3 connect but can’t ses the movement of player 1 and 2
thus, player 1 can see P2 and P3 moving, and P2 can see P3 moving
So i guess it has something to do with my MultiplayerSynchronizer in the player scene but can’t figured out why it’s working in first case but not with the signal emit (second case)
the MultiplayerSynchronizer sync the player position
the goal of the changement is to use an signal to emit() with the player’s id and his pseudo choosed (giving more data). i just could emit an additional signal, but i just want to understand why my code breaks
if you need more code / scene screenshot tell me

