0 votes

Hi everyone,

I have a function instancing a scene with a tween-animation:

func add_that_instanced_scene():

    var scene_with_tween = preload("res://general-stuff/TheScene.tscn").instance()

    add_child(scene_with_tween)

So there is only a sprite within that instanced scene which is being animated by a tween, starting the animation the moment it's added. It queue_free()s itself at the end of the animation.

I'm trying to find a way to „interrupt“ that animation, basically „cancelling“ the instance early under certain circumstances, say on a certain button press for example. Is it possible to „manually queue_free“ an instanced scene while it's „still running“?

Godot version 3.3
in Engine by (492 points)

Tôi củng tùng bị như vậy nhưng có cách giải quyết :)

Well, we're listening ; )

Edit:

Within the same script that instances the scene, I want it to "self destruct" immediately as soon as, in this case, focus_out() happens, so it calls the function nowyouseemenot() within:

func _focus_out():
scene_with_tween.nowyouseemenot()

So within scenewithtween:

func nowyouseemenot():
print ("begone!")
queue_free()

"begone!" is being printed! But the scene is not being destroyed... I tried visible = false as well and for the Child-Node (Sprite) $Sprite.queue_free()... but nothing happens.

What am I missing?

I'd like to add another EDIT:

Pausing appears to fit in this as well. If I pause the game, everything "freezes" properly, except for the instanced scenes - they finish their "cycle" while everything else stands still. So obviously get_tree().paused = true only applies to the scene containing a script with that line but does not apply to any currently instanced scene.
So the question is, how can a currently running instanced scene be integrated into a "pausing"? Any thought on this is much appreciated!

1 Answer

0 votes

And Tween.stop_all ( ) doesn't interrupt animation? It is possible to „manually queuefree(). You do just that call queuefree() on Node you added.

by (889 points)

Thanks for your reply, yrtv.

It's more about the whole instanced scene than only the tween within. I wonder how I can "free a whole scene early" while it's still doing something (like a tween animation for example, but anything really). "un-instancing" a scene (even if it's not "finished" yet), if you will... "destroying" it, so to speak.

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.