This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
+9 votes

I'm using a YSort node to sort my nodes, but my character had a body sprite and a weapon sprite, and I used Z values to switch the weapon from in front of him to behind him, and back again. But that doesn't seem to work well with the YSort because everything seems to stay at Z = 0. So is there a way to switch the position of the weapon sprite with the body sprite, or should I use those Remote nodes, or some other trick?

in Engine by (855 points)

1 Answer

+11 votes
Best answer

I think you should either use the Behind Parent option, or just reorder the nodes in the tree.
Reordering can be done via:

get_parent().remove_child(self)
get_parent.add_child(self)

or

get_parent().move_child(self, index) # Thanks @dc1a0
by (1,608 points)
edited by

there is also:

get_parent().move_child(self, index)

@dc1a0 Thanks, I added it :-)

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 [email protected] with your username.