How to queue free objects in multiplayer?

Godot Version

4.4.1

Question

I’m working on a prototype for a multiplayer survival game in which the players can pick up items. My code only works on the server and I get the errors below. What am I doing wrong here? Doesn’t it suffice to free the Node on the server?

    # in player.gd
    if event.is_action_pressed("pick_up"):
        get_viewport().set_input_as_handled()
        if interaction_ray_cast.is_colliding():
            var maybe_pick_up: Node = interaction_ray_cast.get_collider().owner.owner
            
            if maybe_pick_up is PickUp:
                maybe_pick_up.pick_up.rpc_id(1)
# in pick_up.gd
@rpc("any_peer", "call_local", "reliable")
func pick_up() -> void:
    if multiplayer.is_server():
        queue_free()

CleanShot_2025-05-23_at_16.28.46

E 0:00:25:477   process_rpc: Invalid packet received. Requested node was not found.
  <C++ Error>   Parameter "node" is null.
  <C++ Source>  modules/multiplayer/scene_rpc_interface.cpp:212 @ process_rpc()


E 0:00:25:252   get_node: Node not found: "Game/Level/Objects/RockPickUp" (relative to "/root").
  <C++ Error>   Method/function failed. Returning: nullptr
  <C++ Source>  scene/main/node.cpp:1878 @ get_node()

Are you able to spawn objects in the first place? Do the items have the same readable name between clients?

If you used a MultiplayerSpawner node to replicate this object then it should work, otherwise you will need to rpc from the server to every client to delete the object.

1 Like

I have added the RockPickUp to the scene at compile time for now, I’m not using the MultiplayerSpawner for it at the moment.

I’ve gone for the MultiplayerSpawner approach, but rpc works too. Thank you!