The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

0 votes

There's a code

 #---------------------------------FIRST VER-----------------------#
    func _process(delta):
        yield(get_tree().create_timer(1), "timeout")  #-----> not necessarily
        $lighter/AnimationPlayer.play("light_break")

Works perfectly well until I try to start from "menu" scene. Player starts lag and nothing is happens on scene. That's in second room, first works brilliant. And it also works perfectly when player moves from scene to scene.

Also i tried to give other scene and start from the menu, but... then player doesn't even contact with it.
here's the trigger code:

func _physics_process(delta):
    var bodies = get_overlapping_bodies()
    for body in bodies:
        if body.name == "frisk":
            get_tree().change_scene("*some_scene*")

What can i do with it?

Godot version 3.2.3 stable
in Engine by (32 points)

To help with the "lagging" part, instead of using get_overlapping_bodies(), use signals instead. The function get_overlapping_bodies() can be process-intensive, and so can lead to sluggish frames.

Agreed get_overlapping_bodies() should only ever be used as a test case and not in the way it is here

thanks a lot

1 Answer

+1 vote
Best answer

The _process function is called every frame. You shouldn't be using "yield" in it. I'm not sure what the script is on, but based on the error it's on a node that's freed when the scene is changed, so you shouldn't do that.

You also shouldn't check the overlapping bodies each frame either. Instead, go into the signals tab and connect the "body_entered" signal and check the body there.

by (8,550 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 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.