Best way to pause a Node and instantly move it after pause?

Godot Version

4.4.1

Question

Hello, does anyone know a good way to “pause” a node and instantly move it to another location? I’m working on a re-spawn mechanic for players. I don’t want to delete the player node but I do want to remove them from physics and then re-spawn them in a random location after a short break. Currently, I set process_mode to PROCESS_MODE_DISABLED but this fails on the re-spawn because I cannot instantly set the new position in the physics server and avoid triggering collisions in the previous location. Areas and raycasts still trigger in the old location for one frame and force_update_transform does not help. I also don’t want to remove them from the tree, if possible, because I use the tree_exiting signal as a destructor…
Any ideas appreciated!

I think just remove_child(player_node) is sufficient to get it out of the tree and stop processing.

Then just add change its position for the respawn and calling add_child again.

NOTE: the _ready function is only called once unless you reset the ready state with player_node.request_ready()

You could change this to NOTIFICATION_PREDELETE in _notification() callback.

Or you can use is_queued_for_deletion check during the exit tree signal.

I do this with a teleport function for my player.

What I do is first call a disable function on my player, this in effect removes the player from the scene by making them invisible, disabling collision shapes, stopping player inputs and stopping any processes from running etc etc.

# This is from my actual code just as an example

func disable_player_ship(new_state: bool) -> void:
	INPUT_MANAGER.set_process_input(not new_state)
	GAME_LEVEL.UI.show_touch_buttons(not new_state)
	SHIP_COLLISION_AREA.call_deferred("set_disabled", new_state)
	SHIELD_COLLISION_AREA.call_deferred("set_disabled", new_state)
	MOVEMENT_MANAGER.pause_movement(new_state)
	LIFE_MANAGER.pause_shield_charging(new_state)
	SPECIAL_ABILITIES.pause_all_abilities(new_state)
	WEAPONS_MANAGER.set_weapon_firing(not new_state)
	SHIP_BODY.visible = not new_state
	SHIP_ENGINES.visible = not new_state
	is_collecting = not new_state

So I just disable the player, then I do the teleport, which is the camera scrolling across the map to the new teleport position. When the camera is in place I set the players new position and re-enable the player again. There are some teleport affects that cover the players sudden disappearance and reappearance in my particular case, but you could just as easily tween them out of the scene and tween them back in again.

I think removing from the tree and adding back in again would cause me lots of problems that I avoid just by ‘turning off’ the player during the teleport.

Hope that helps in some way.

Went with everyone’s favorite solution, add another autoload! Made a node stasher that moves the node to (9999, 9999, 9999), in the absence of a sane physics API I think this is actually not a terrible solution. Marking this as the solution because it’s a good idea and I didn’t know about is_queued_for_deletion.