MultiplayerSpawner logic and mechanic

Hi everyone!

I’m trying to implement multiplayer features and I’m trying to understand how MultiplayerSpawner works.

  1. What’s the use of MultiplayerSpawner? I read that this will spawn an object that will be replicate for all peers, server included. Is that right?
  2. The MultiplayerSpawner has a spawn_path that you should assign a node. Will this be the node that will spawn the objects? Will this be the position where the object will be spawned?
  3. Also, MultiplayerSpawner has a spawnable scene that will be the scene spawned. How do I spawn them? Should I use a regular instantiating and add_child method?
  4. Finaly, the class has spawn_limit property. I understand that this is the limit of objects that can be spawned from that spawner. If I want multiple positions to serve as spawner places, should I use multiple MultiplayerSpawner, each one of them with their own spawn_path?

I also understand that I will need the MultiplayerSynchronizer in the objects to choose which properties are going to be replicated to all peers, but that will be another question.

1 Like

Yes it ill spawn a scene to all pears, but… the authority ( default is the host ) needs to instantiate() a scene that is on the spawn list and add_child() to the spawner’s watched node path.

No, just where add_child() should be called and any node of the spawner’s authority can call it (e.g. an entity system or object factory). just needs to be added as child to the watched node path.

And yes this will be the default position on the remote peers where it is spawned.
(note: all properties of the scene will be in a defaults state, use a custom spawn, or MultiplayerSynchronizer to initialize state.)

yes, just instantiate them like you normally would, on the authority, and add them as a child to the watched spawn path.

This is an option, you can also setup a custom_spawn function where you can provide the spawn position to the remote peers before the new scene is spawned. Or, depending on your network architecture, just use a MultiplayerSynchronizer to update the position on spawn.

Just be aware that node authority matters, and authority defaults to the server. And to despawn a node, the spawner authority should be the only one to call queue_free() or remove_child() on the spawnable scenes.

3 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.