0 votes

i've got a playerscene that i imported into my map. The player contains of an position 3d, a Camera and a collisionshape.
now im triying to parent an object in this map via the script of the player to the players position 3d. i tried it like so:

var new_parent = get_node("Area/Position3D")
get_parent().remove_child("object of map")
new_parent.add_child("object of other world")

but this doesnt work, and i think its because the object is in another scene.
has someone an idea?

(sorry for my bad english)

Godot version 3.3
in Engine by (213 points)

1 Answer

0 votes

If this "another scene" is not part of the sceneTree then your attempt is not possible

If your intention is to move a node between changed scenes then your best option would be to save it to a var possibly in an Autoloaded node then add after scene change

Assuming that is not the case and your node has been properly added to the sceneTree then it's simply a matter of referencing the proper nodePath, look in the remote dock on game launch to find that out.

Your node must be instanced to be added so even if temporarily load that PackedScene then add to the sceneTree where needed

by (5,012 points)

Nice, now it works.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.