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.
0 votes

I have two KinematicBody2D nodes with circle collision shapes. Body1 stays in one spot calling move_and_collide(Vector2.ZERO) every _physics_process. Body2 is initially colliding with Body1 and then every _physics_process calls move_and_collide to move away from Body1.

If Body1 detects a collision it calls get_tree().set_deferred("paused", true), waits one second, then unpauses. It then enters an infinite loop, detecting a collision on every physics step, even as you can see Body2 moving farther and farther from Body1.
If I comment out the line that pauses the scene tree, only 1 collision is detected and the scene works as expected.

Am I missing something or is this a bug? Any workaround?

Below is the code for Body1:

extends KinematicBody2D

func freezeFrame(duration):
    get_tree().set_deferred("paused", true)
    yield(get_tree().create_timer(duration), "timeout")
    get_tree().paused = false

func _physics_process(delta):
    if move_and_collide(Vector2.ZERO):

EDIT: Here's a link to the example project. Please enable Visible Collision Shapes in the Debug menu. If you run the project you'll see the infinite loop I'm talking about. If you comment out the line that paused the tree it runs perfectly.

Godot version 3.4.4.stable.official
in Engine by (17 points)
edited by

1 Answer

0 votes

I am not sure if I understand, but is it that You want to pause only one node ?
Setting Tree.paused pauses whole tree and mutliple functionality of built-in servers. Whole PhysicsServer also becomes paused, and collision detection along with it. Collision shapes will not work because of this, even if they are set to ignore pause. The only thing, that doesn't get paused are actually dynamic timers, which is rarely beneficial. If You want to pause just one body, You will have to do it manually, design what is supposed to be frozen among this body functions.

by (8,188 points)

Thanks for responding, no I'm not trying to pause only one node, I'm trying to pause the entire screen for a short period, then resume as normal.

For context, I want to freeze the frame on collision to produce a hit-stop kind of effect.
What should happen in my eyes is

  1. A collision is detected
  2. The physics frame finishes, resolving the collision
  3. The tree is paused (from the deferred set call earlier)
  4. One second passes
  5. The tree is unpaused
  6. The collision is no longer detected (as the 2nd body has been moved)

What I'm seeing is that on step 6 above, the collision is still detected on every subsequent _physics_process call after unpausing.

I see
You are calling yield in subroutine coming from physics process. I suspect freezeframe() receives a large chunk of calls before deferred frame, so it repeats pausing and unpausing in duration intervals for quite some time. But not infinitely. Did You try to pause without deferring ? If this doesn't work or You can't, try to fit whole code in physics_process, without subroutine.

No dice, if I set the paused = true immediately, the physics process is cut off and the 2nd body never gets to move, so the collision is always happening.

I tried moving the code out of the subroutine and into the _physics_process but it has the same exact result. I don't think the issue is a large number of buffered pauses because if I add print to the function I see the prints happening once per _physics_process
Also I see the 2nd body continuously moving away with each pause/unpause cycle.

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.