can_process: "!is_inside_tree()" is true. Returned: false

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

Hey, I’m new and I was doing several tutorials when i found the error in the title

I wrote a code where if a ball gets out of the screen, several things happen:

func _on_VisibilityNotifier2D_screen_exited():
var replay_scn = load("res://title/replay.tscn")
lose_s.play()
get_tree().paused = true
yield(lose_s,"finished")
queue_free()
get_parent().add_child(replay_scn.instance())

 

there is a part of the code when I press a button

func _input(event):
if event.is_action_pressed("iniciar") and not iniciado :
	iniciado=true 
	linear_velocity=Vector2(50,-500)
	start_s.play()
	set_as_toplevel(true)
elif event.is_action_pressed("iniciar") and iniciado==true :
	get_tree().change_scene("res://World.tscn") ###ERROR HAPPENS HERE####
	start_s.play()
	set_as_toplevel(true)
	get_tree().paused=false

When I change the scene in this point, the following error appears

can_process: “!is_inside_tree()” is true. Returned: false

and after that I am not able to unpause the game and it freezes

I am also noob in terms of formullating questions, so if you need more information, i’ll give you.

Ty guys and sorry for bad indentation in code copying

:bust_in_silhouette: Reply From: bloodsign

I don’t have the exact answer to your problem, but I stumbled across on that error myself.
It usually happens when you instance something, apply properties to it before adding it to the scene tree(sorry if I made it more confusing, English isn’t really my first language). To illustrate:

var camera_pck = preload("res://custom_camera.tscn")
var camera = camera_pck.instance

camera.global_position.x = 900
add_child(camera)

These snippet of code would generate this error:

get_global_transform: Condition “!isinside_tree()” is true. Returned: get_transform()

In order to fix it I just move

camera.global_position.x = 900

after add_child(camera), likeso:


add_child(camera)
camera.global_position.x = 900
1 Like