GrapeSodaGames / Multiplayer

0 stars 0 forks source link

Players should spawn in when the game starts #153

Closed zaphodb2002 closed 3 months ago

zaphodb2002 commented 3 months ago

Okay, things have been rough lately but I have a little bit of time today to get some work done. However, of course, I have run into an unexpected problem. The multiplayer syncing now seems to not be working, despite no changes in the last couple of weeks. The actual connecting and creating the players seems to work, but the UI seems to think that I am all players on all clients. There's a function in there, something like is_local_player(), that does this. A good place to start looking.

zaphodb2002 commented 3 months ago

Alright back to this. Currently we are just calling _player_spawner.spawn() in World._ready(). This does appear to spawn a single player on both clients. However, we're getting a c++ error:

E 0:00:14:0682   world.gd:19 @ _ready(): Condition "!is_inside_tree() || !get_multiplayer()->has_multiplayer_peer() || !is_multiplayer_authority()" is true. Returning: nullptr
  <C++ Source>   modules/multiplayer/multiplayer_spawner.cpp:322 @ spawn()
  <Stack Trace>  world.gd:19 @ _ready()
                 game_state.gd:106 @ load_world()

So, when is this getting called? GameState has load_world() which is an rpc. It instantiates the player, then adds them to the tree. This is the issue here because we need the multiplayer info to correctly spawn, but we don't have that until we're in the tree.

zaphodb2002 commented 3 months ago

157 is my solution. However, I am still getting an error on spawn on the guest client(s).


E 0:00:08:0560   on_spawn_receive: Condition "parent->has_node(name)" is true. Returning: ERR_INVALID_DATA
  <C++ Source>   modules/multiplayer/scene_replication_interface.cpp:604 @ on_spawn_receive()

This doesn't seem to affect functionality, though. All players seem to spawn correctly and the Actor.setup() is getting applied appropriately, including changing the name. We might be able to fix it using a custom spawn function instead but for now this is good enough. If it causes problems down the line, we'll revisit.