I've created a new instance, positioned it, and added it to the scene like this:
const Player = preload("res://player.tscn")
func _physics_process(delta):
if <outside display>:
var newplayer = Player.instance()
newplayer.position.x = 200
get_tree().get_root().add_child(newplayer)
queue_free()
This works to the extent that the player is created in the right position and starts falling down with gravity. But the new player does not respond to any input, nor does it do anything if I print things in the _ready function or the _physics_process function. It seems its script is just never executed at all.
I've tried not queue_free()'ing the old one, in case removing it is like removing its parent, but that doesn't help.
I've tried calling the ._ready() function on it manually, but that doesn't work either.
I've tried calling request_ready() on the new player, but that doesn't run the _ready() function either.
In tutorials, this is usually all they do to get a new instance into the world, so I'm not sure what I'm missing here.
set_physics_process(true)in the_readyfunction. It's the only script I have at the moment. My root node isworld(just a node) withplayer(RigidBody2D) as only relevant child (and some unused, static object calledtargetas other child). Theplayerhas a Sprite and CollisionShape2D as children. Any idea what could be missing? \$\endgroup\$<outside display>? -- I've created a simple example similar to yours in which I just move the player object to the right and spawn new players by pressing a key and it works correctly. BTW, thepreloadcauses an errorpossible cyclic resource inclusion, but the program still works so I'm not sure if it has to do with the problem (I replaced it withload). \$\endgroup\$newplayer.set_script(...). \$\endgroup\$