• Godot Help
  • Issue synchronizing node with programatically added child node in multiplayer

I'm currently trying to get item pickups to work in multiplayer, I programmatically add the sprite from the weapon the pickup corresponds to. The pickups spawn correctly in the host, but in the clients, the pickups spawn without the corresponding sprite node as children.

function in map

var available_pickups = [{'pickup':preload("res://scenes/weapons/test_weapon.tscn"), 'weight':100, 'scene':"res://scenes/weapons/test_weapon.tscn"}]

func spawn_pickups():
    var total_weight = 0
    #weighted random
    for pickup in available_pickups:
        $MultiplayerSpawner.add_spawnable_scene(pickup['scene'])
        total_weight += pickup['weight']
    for location in $PICKUPS.get_children():
        var rng = RandomNumberGenerator.new()
        var random_num  = rng.randi_range(0, total_weight)

        for pickup in available_pickups:
            if(random_num<= pickup['weight']):
                var pu = pickup['pickup'].instantiate()
                var pickup_node = pu.drop_on_location(location.global_position, self)
                break
            else:
                random_num -= pickup['weight']

pickup generating function in weapon

func drop_on_location(location: Vector2, father_node: Node):

    var pu:Pickup = pickup.instantiate()
    pu.isWeapon = true
    var newscene = PackedScene.new()
    newscene.pack(self)
    pu.resource = newscene
    pu.set_global_position(location)
    pu.set_rotation(rotation)
    var sprite = get_center_marker().get_child(0).duplicate()

    pu.add_child(sprite)

    father_node.add_child(pu, true)
    
    queue_free()
    return pu

Host function where spawn_pickups is called

func host_game():
    hud.visible = false
    enet_peer.create_server(SERVER_PORT)
    multiplayer.multiplayer_peer = enet_peer
    multiplayer.peer_connected.connect(add_player)
    add_player(multiplayer.get_unique_id())
    spawn_pickups()
    map.visible = true

Any help is greatly appreciated!



    kuligs2 Thanks for the response, I did try using an rpc function and the problem persists there as well, host spawns pickups with sprites, clients only spawn them without sprites

      birucan how do you add sprites to pickup? maybe you need to wrap that function in rpc too?