0 votes

I'm making a game where coins spawn, one of the characters of the game walks around the scene and spawn coins, due to some functions, I decided to create like a core coin that is cloned and then changes the position of the cloned coin to the character's position.

I tried using duplicate() but didn't work, I thought it doesn't duplicate sub-nodes so I decided testing cloning the sprite and changing its position, the console says the position where it was changed, but in-game it doesn't show in that position.

Basically, the code is like this:
func on_timeout(): var thingy = get_parent().get_node("Group/Coin") var thingyTwo = thingy.duplicate() thingyTwo.position.x = 0 print(thingyTwo.position.x)

in Engine by (60 points)

1 Answer

+1 vote
Best answer

you duplicated it but did not add it to the scene tree.

func on_timeout():
        var thingy = get_parent().get_node("Group/Coin")
        var thingyTwo = thingy.duplicate()
        thingyTwo.position.x = 0
        print(thingyTwo.position.x)

for example;

func on_timeout():
        var thingy = get_parent().get_node("Group/Coin")
        var thingyTwo = thingy.duplicate()
        thingyTwo.position.x = 0
        someNode.addchild(thingyTwo) #Add to scene tree
        print(thingyTwo.position.x)
by (154 points)
selected by
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 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.