Tweens stopping on reparenting a node

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By indy2005


I have a sprite which pulses on a tween loop with yield. In the root nodes script I am getting this sprite to alternate between 2 Path2DFollow nodes. To do this I am reparenting the Sprite node from one path node to another. This works…but what happens is, all the tweens (pulsing) in the child node stop…I am assuming because briefly the child is leaving the scene tree? The tween is a sibling to the Sprite, not a child.

This seems to solve it. Am I right to assume if you move a child node from a scene, all tweens get “stopped” or “paused” and I have to resume them once I reparent the node and add it back to the scene?

func _enter_tree():	
	print("Player entered the scene tree....")
	if tween != null:

i guess you dont have to reparent the sprite to do so.

Maybe you want to share more code to get an alternative.

klaas | 2020-09-17 21:22

I guess the question is…what happens when you remove a node from the tree, even if temporarily. Does the process step stop? Do Tweens get stopped or paused?

indy2005 | 2020-09-17 21:29

ok, would assume to test before asking but … nevermind

I tested, they get paused amd can get resumed.

klaas | 2020-09-17 21:49

I did test which is why I got it working with resume_all. But what else stops, does everything get paused including _process etc. Thanks for testing, explains a few strange bugs I was seeing. If the answer is, nothing executes at all when out of the tree, I need to be more careful. How you get a sprite to alternate between two path follows without reparenting…I have no idea

indy2005 | 2020-09-17 21:53

Nodes that are not in the sceneTree get no _process, _physics_process etc. notifications and alike. As soon they are back in the SceneTree they get those notifications again.

I think there is no list of those behaviours anywhere in the docs. But removing something from the tree is allways somewhat “risky” and can break things easily. Its best to avoid unless its necessary.
Dont get me wrong … its totaly legit but must be done carefully.

klaas | 2020-09-17 22:02

Thanks…,I would imagine reparenting is quite a common technique? I am doing it to ‘pin’ one object to another, basically by making it a child of the target node…it looks like it stuck to it. You can’t reparent without briefly taking it out of the tree. At least I don’t think you can . If this screws up tweens, animation states…that’s a problem. It would be great if Godot introduced a reparent() method which kept continuity of processing.

indy2005 | 2020-09-17 22:08

I agree … that would be nice to have. If you want to pin things to another thats the way to go.
But there are many this to take care of. By example relative NodePath can fail cause they wont get updated.
Its just about how you set it up to avoid those issues.

klaas | 2020-09-17 22:16