_process() stops getting called after change_scene

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

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.

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 SceneTree — Godot Engine (3.3) documentation in English :

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()

timothybrentwood | 2021-05-05 00:24

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)

Wavesonics | 2021-05-05 00:30

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

timothybrentwood | 2021-05-05 01:02

:bust_in_silhouette: Reply From: MagnusS

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.