Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | sygi |
I read this tutorial on scene replication. I would like to do something similar, where I have:
- two users who join a lobby one after another
- each user has authority over its respective player (not just the input, like in the tutorial)
- replication of the player across users (each user controls their own player)
- synchronization of some of the properties of the players
I managed to achieve this goal by following this sketch:
class players
func _ready():
multiplayer.peer_connected.connect(add_player)
func add_player(id: int):
var character = preload("res://players/player.tscn").instantiate()
character.set_multiplayer_authority(id)
add_child(character)
class UI
func _on_joining_lobby():
get_node("/root/root/players").add_player(multiplayer.get_unique_id())
and player scene having a Synchronizer. I don’t like it, as it relies on doing the spawning manually (the character is created on joining lobby and then I explicitly add its copy when the peer connects): this makes it harder to use the “spawn” functionality on the synchronizer, as it only seem to trigger when the spawn happens through the Spawner.
Is there a way to achieve that behavior with the MultiplayerSpawner? Is there a better way at all?
I tried to replace the extra spawn on connection with a Spawner but then it complains about the change of the node’s authority, even if I do it in enter_tree
(and also seems to only trigger for the server user, presumably due to Spawner/players’s authority itself).