Game freezing permanently for unknown reasons

CyberJellyCyberJelly Posts: 3Member
edited June 9 in 2D

So the basic setup of the error is that two levels are added immediately. Then, whenever the player reaches a certain point and collides with an Area2D node it should add a new level (levels stored in separate scene).

The code is split up into code for the main Node2D (World) and an Area2D (NextLevel) with a CollisionShape2D. The Area2D is in the level1 scene while the Node2D is in the main scene.

Relevant Code for World Node2D

extends Node2D
onready var level1 = preload("res://level1.tscn")
onready var level2 = preload("res://level2.tscn")
var levels = 1
func _ready():
    var level1i = level1.instance()
    var level2i = level2.instance()
    level2i.position.y += -2048

func _newLevel():
    print("new level")
    var level1i = level1.instance()
    level1i.position.y += -2048*levels

Code for NextLevel Area2D
`extends Area2D

onready var world = get_node("/root/World")
func _on_NextLevel_body_entered(body):

So, to get to the point, for some reason, whenever the player collides with the Area2D and triggers _on_NextLevel_body_entered, the game completely freezes. No errors, it just freezes.

What is even more strange is when it does freeze, the variable (body) is not printed, and neither is "new level", yet when I remove the line "add_child(level1i)" both are printed, although now the game doesn't function properly.

Sorry for spaghetti code, pretty new to Godot.

Also, I just realised that when it is frozen, this message comes up in the command prompt window that opens with Godot:

At: servers/physics_2d/physics_2d_server_sw.cpp:739

ERROR: Can't change this state while flushing queries. Use call_deferred() or set_deferred() to change monitoring state instead.

Tags :

Best Answer

  • bitshift-rbitshift-r Posts: 55
    Accepted Answer

    In _on_NextLevel_body_entered you could try world.call_deferred("_newLevel"). Godot doesn't like you changing things during a physics update.


Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file