I tried to make a multiplayer game using Godot's built in Spawner and Synchronizer , I have invested more than 30hours to fix this , just 60 lines of code, and I still haven't succeeded because there isnt a proper tutorial for this. Everyone uses a combinaton of rpcs and built in modules. Sometimes I feel like they are meant to work together , other times ive heard tutorials say - "You dont need rpc , use built in modules".
I am exhausted till de***, I cant take this anymore , I have a project to submit hence here is my Networkmanager.gd which is the closest that ive ever been to the desired output.
In this version. All connected "clients" except the host server are synchronized for all. Its only the server player whose movement isnt synchronized , I can move it in the server machine, but the clients do not show it moving.
I hope someone could point the error.

extends Node

var MAX_CLIENTS = 8
var PORT = 8090

var peer = ENetMultiplayerPeer.new()
var lobby_scene = preload("res://scenes/maps/Spaceship.tscn")
var player_scene = preload("res://scenes/player/player.tscn")

func _ready() -> void:
	pass

func host_game():
	peer.create_server(PORT, MAX_CLIENTS)
	multiplayer.multiplayer_peer = peer

	# host loads the map
	add_child(lobby_scene.instantiate())
	_on_player_connected(multiplayer.get_unique_id())                            # host (ENet=1)
	multiplayer.peer_connected.connect(_on_player_connected)
	multiplayer.peer_disconnected.connect(_on_player_disconnected)
	multiplayer.connection_failed.connect(_on_connection_failed)
	multiplayer.server_disconnected.connect(_on_player_disconnected)
	
func join_game():
	peer.create_client("::1", PORT)
	multiplayer.multiplayer_peer = peer

	# **client also loads the map**
	add_child(lobby_scene.instantiate())

	await multiplayer.connected_to_server

	_on_player_connected(multiplayer.get_unique_id())  # you
	multiplayer.peer_connected.connect(_on_player_connected)
	multiplayer.peer_disconnected.connect(_on_player_disconnected)
	multiplayer.connection_failed.connect(_on_connection_failed)
	multiplayer.server_disconnected.connect(_on_player_disconnected)

func _on_player_connected(id):
	if has_node(str(id)):
		return
	print("add player called for:", id)
	var player = player_scene.instantiate() as CharacterBody2D
	player.name = str(id)
	player.set_multiplayer_authority(id)
	player.position = Vector2(
		randi_range(970, 1030),
		randi_range(480, 520)
	)
	add_child(player)

func _on_player_disconnected(id:int) -> void:
	if has_node(str(id)):
		get_node(str(id)).queue_free()

func server_disconnected():
	multiplayer.multiplayer_peer = null

func _on_connection_failed():
	multiplayer.multiplayer_peer = null
  • kuligs2 replied to this.
  • What ultimately fixed the problem makes no sense. But I'll still put it up.

    The Multiplayer Spawner has "Spawn path" set to the SpawnRoot node.

    extends Node
    
    var MAX_CLIENTS = 8
    var PORT = 8090
    
    var peer = ENetMultiplayerPeer.new()
    var lobby_scene = preload("res://scenes/maps/Spaceship.tscn")
    var player_scene = preload("res://scenes/player/player.tscn")
    
    func _ready() -> void:
    	multiplayer.peer_connected.connect(_on_player_connected)
    	multiplayer.peer_disconnected.connect(_on_player_disconnected)
    	multiplayer.connection_failed.connect(_on_connection_failed)
    	multiplayer.server_disconnected.connect(_on_player_disconnected)
    	
    
    func host_game():
    	peer.create_server(PORT, MAX_CLIENTS)
    	multiplayer.multiplayer_peer = peer
    
    	# host loads the map
    	$SpawnRoot/lobby.add_child(lobby_scene.instantiate())
    	_on_player_connected(multiplayer.get_unique_id())                            # host (ENet=1)
    	
    func join_game():
    	peer.create_client("::1", PORT)
    	multiplayer.multiplayer_peer = peer
    
    	# **client also loads the map**
    	$SpawnRoot/lobby.add_child(lobby_scene.instantiate())
    
    	await multiplayer.connected_to_server
    
    	_on_player_connected(multiplayer.get_unique_id())  # you
    	
    func _on_player_connected(id):
    	if has_node(str(id)):
    		return
    	print("add player called for:", id)
    	var player = player_scene.instantiate() as CharacterBody2D
    	player.name = str(id)
    	player.set_multiplayer_authority(id)
    	player.position = Vector2(
    		randi_range(970, 1030),
    		randi_range(480, 520)
    	)
    	$SpawnRoot/player.add_child(player)
    
    func _on_player_disconnected(id:int) -> void:
    	if has_node(str(id)):
    		get_node(str(id)).queue_free()
    
    func server_disconnected():
    	multiplayer.multiplayer_peer = null
    
    func _on_connection_failed():
    	multiplayer.multiplayer_peer = null

    Each scene such as lobby_scene had to be inside their own node inside the spawnRoot node, If I put the player scene inside the SpawnRoot/player and lobby inside the SpawnRoot/ , it wouldnt work , it has to be SpawnRoot/lobby and viceversa.
    Explanation? None

    Yashx9201 It takes many mistakes, to get it right. Dont give up.

    And you gotta change the attitude buddy, aint nobody gon fix your problems. If you need help then ask for help, not demand it.

    You haven't even described the error you are getting. So whats the problem?

    Check posts on this thread maybe youll get some ideas https://godotforums.org/d/40012-synchronizing-multiplayer-3d-cameras-and-items-fail/5

    Maybe even here https://godotengine.org/article/multiplayer-in-godot-4-0-scene-replication/

      kuligs2

      kuligs2 And you gotta change the attitude buddy, aint nobody gon fix your problems. If you need help then ask for help, not demand it.

      No where did I mention to fix my problems, I didnt ask for a code-rewrite , I simply said "I hope someone could point the error.".
      And Ive been through forums where people point out the "conventional" mistakes, which is fine by me most of the times it made sense, but the scripts behavior changes with how many times and places ive entered the same lines of code.
      Although , I will remove those lines in my post (not the code) and let that happen.

      kuligs2 You haven't even described the error you are getting. So whats the problem?

      Im pretty sure I marked that in the bold.

      What ultimately fixed the problem makes no sense. But I'll still put it up.

      The Multiplayer Spawner has "Spawn path" set to the SpawnRoot node.

      extends Node
      
      var MAX_CLIENTS = 8
      var PORT = 8090
      
      var peer = ENetMultiplayerPeer.new()
      var lobby_scene = preload("res://scenes/maps/Spaceship.tscn")
      var player_scene = preload("res://scenes/player/player.tscn")
      
      func _ready() -> void:
      	multiplayer.peer_connected.connect(_on_player_connected)
      	multiplayer.peer_disconnected.connect(_on_player_disconnected)
      	multiplayer.connection_failed.connect(_on_connection_failed)
      	multiplayer.server_disconnected.connect(_on_player_disconnected)
      	
      
      func host_game():
      	peer.create_server(PORT, MAX_CLIENTS)
      	multiplayer.multiplayer_peer = peer
      
      	# host loads the map
      	$SpawnRoot/lobby.add_child(lobby_scene.instantiate())
      	_on_player_connected(multiplayer.get_unique_id())                            # host (ENet=1)
      	
      func join_game():
      	peer.create_client("::1", PORT)
      	multiplayer.multiplayer_peer = peer
      
      	# **client also loads the map**
      	$SpawnRoot/lobby.add_child(lobby_scene.instantiate())
      
      	await multiplayer.connected_to_server
      
      	_on_player_connected(multiplayer.get_unique_id())  # you
      	
      func _on_player_connected(id):
      	if has_node(str(id)):
      		return
      	print("add player called for:", id)
      	var player = player_scene.instantiate() as CharacterBody2D
      	player.name = str(id)
      	player.set_multiplayer_authority(id)
      	player.position = Vector2(
      		randi_range(970, 1030),
      		randi_range(480, 520)
      	)
      	$SpawnRoot/player.add_child(player)
      
      func _on_player_disconnected(id:int) -> void:
      	if has_node(str(id)):
      		get_node(str(id)).queue_free()
      
      func server_disconnected():
      	multiplayer.multiplayer_peer = null
      
      func _on_connection_failed():
      	multiplayer.multiplayer_peer = null

      Each scene such as lobby_scene had to be inside their own node inside the spawnRoot node, If I put the player scene inside the SpawnRoot/player and lobby inside the SpawnRoot/ , it wouldnt work , it has to be SpawnRoot/lobby and viceversa.
      Explanation? None