0 votes

I've got a real head scratcher. I've been debugging this for months and haven't managed to crack it.

tl;dr:
I have a scene, some times when I change to that scene, the _process() methods don't get called while that scene is alive.

Other methods, like those that result from network activity work just fine, and if the scene is switched away from, everything continues to work, even eventually switching back to that scene, it's _process() methods will begin getting called again.

Deeper dive:
It's a multiplayer game, and this is a problem on the dedicated server.

I have two main scenes: Lobby & Game, and I change between them using the standard change_scene() method

Some times when switching back from Game to Lobby after a match, Lobby's (and all of it's children's) _process() method will just never get called.

It is seemingly random, I still after 6 months of searching not found a solid repo.

There's no errors in the the terminal. I've even run the server in debug, attached to the editor, to try and catch this, and the editor doesn't hit any errors.

When it gets into this state I've even set break points in the Lobby's _process method, and it never gets hit.

Everything else works just fine, people can join and leave the lobby, even start the game, because those are all triggered from user or network (RPC) input.

If you start a game, finish, return to Lobby, it's fixed, and the _process methods start firing again.

If anyone has any thoughts, no matter how crazy, I'm all ears, b/c I'm pretty out of ideas my self.

Godot version 3.3
in Engine by (30 points)

I don't think _process() will get called at all in the scene that you change away from. I think this is normal behavior?
From https://docs.godotengine.org/en/3.3/classes/class_scenetree.html#class-scenetree-method-change-scene :

Error change_scene(path: String)

Changes the running scene to the one at the given path, after loading it into a PackedScene and creating a new instance.

a.gd:

extends Node2D

var time = 0
func _ready() -> void:
    print("a ready")

func _process(delta: float) -> void:
    time += delta
    if time > 1:
        print("a")
        time = 0

func _input(event: InputEvent) -> void:
    if event.is_action_released("mb_left"):
        get_tree().change_scene("res://b.tscn")

b.gd:

extends Node2D

var time = 0
func _ready() -> void:
    print("b ready")

func _process(delta: float) -> void:
    time += delta
    if time > 1:
        print("b")
        time = 0

func _input(event: InputEvent) -> void:
    if event.is_action_released("mb_left"):
        get_tree().change_scene("res://a.tscn")

Every time you click _ready() is called for the new scene and the old scene stops its _process()

Sorry if I wasn't clear. If I switch TO the Lobby, the Lobby's _process method is not called.

Indeed as expected, when switching AWAY from the Lobby, the _process method stops getting called (if it had not been experiencing the bug where it was already not being called)

Ah yes, you were clear, sorry I misread. Stupid question but I assume you've tried something like this?:

var err = get_tree().change_scene("res://b.tscn")
if err == OK:
    pass
elif err == ERR_CANT_CREATE:
    breakpoint
elif err == ERR_CANT_OPEN:
    breakpoint

1 Answer

0 votes

Tbh, if it works sometimes, but not always, there's a high chance that this is a problem with Godot itself. Have you looked through the github issues? Maybe some people have the same problem. Otherwise, the only thing I can imagine is, that you have a "set_process(false)" somewhere in your scripts.

by (290 points)
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.