Godot Version
4.4-dev2
Scenario
I’m creating a basic platformer that has coins and mobs at certain locations in the level. I’d like to synchronize the coins and mobs using a MultiplayerSpawner so that I can handle destroying them on the server when the player collects the coins or kills the mobs and have that be synchronized to all clients.
Question
MultiplayerSpawner works great when you spawn objects after clients have connected (like spawning a Player object when a new client connects), but how can it work with pre-existing objects (coins/mobs that are already on the map)?
If I just set up a MultiplayerSpawner with the Coin scene in the Auto Spawn List and Spawn Path set to the parent of some coins in the scene, it will cause this error to appear when a client connects because the client already has the coins when the server tries to sync them:
SceneReplicationInterface::on_spawn_receive: Condition “parent->has_node(name)” is true. Returning: ERR_INVALID_DATA
Possible Solution 1
I’ve tried deleting objects from clients before they’re synchronized, but queue_free()
isn’t called until after the MultiplayerSpawner tries to sync objects, so it results in the same error.
Possible Solution 2
I’ve tried renaming objects (and later deleting them) on clients before they’re synchronized, but that seemed to break synchronization and the coins were not recreated by clients when the server tried to sync.
Possible Solution 3
Would the best solution be to create a placeholder object for coins/mobs for level creation and then, at runtime, delete the placeholder and have the server replace them with coins/mobs to synchronize to clients? This sounds like it would work, but would be less convenient for level design.
Please let me know what you think the best solution would be in this situation or if there is a better solution than the ones that I have listed. Thank you!