Nested spawning not replicating

Godot Version

4.3 Stable

Question

I am spawning some nodes on a server and replicating them with MultiplayerSpawner. I am having issues replicating on clients.

The intended hierarchy is:

  • Crate
    • Item
      • Item Data

The server successfully instantiates this hierarchy. The replicas only produce:

  • Crate
    • Item

The code being ran (from a crate) is:

@rpc("any_peer", "call_local", "reliable")
func _interact(id):
	if !multiplayer.is_server(): return
	var new_item = item.instantiate()
	var item_data = items[item_type].instantiate()
	add_child(new_item, true)
	new_item.add_child(item_data, true)

There is a MultiplayerSpawner on the crate (which has Item as an autospawn), as well as a spawner on the Item (which has ItemData) as an autospawn.

I am confused as to why the Items replicate as intended, but the child itemdata nodes do not.

Edit:
I have quickly got around this issue by delegating the second add_child to the child itself.

I am still curious as to where my knowledge of replicas and MultiplayerSpawner failed in the case provided.

Could you post the code you used to workaround this issue? It could be a bug in MultiplayerSpawner.

I delegated the second add_child call to the child itself.

The original _interact/1 method hence becomes:

crate.gd:

@rpc("any_peer", "call_local", "reliable")
func _interact(id):
	if !multiplayer.is_server(): return
	var new_item = item.instantiate()
	new_item.set_data(item_type)
	add_child(new_item, true)

Where set_data/1 is responsible for determining the nested node to spawn. This can then be instantiated in the Item’s _ready/0 function.

item.gd:

func set_data(data_type: GameManager.ITEM_TYPE):
	type = data_type

func _ready():
	if type && multiplayer.is_server():
		var item_data = items[type].instantiate()
		add_child(item_data)

I made no changes to the setup of the MultiplayerServer; however this now replicates as I would have expected.

1 Like