User:Senka/a bas nije da nas nikad nije bilo/Godot Debugging
Debugging
Portals
There's a documentation page for portals and rooms [1] but it's outdated (made for Godot 3.5, I'm using 4.3).
Portals to different rooms This needs a lot of reorganizing of the code for it to work... Currently stuck at trying to delete one room once there has been a switch from another (queue_free function not working).
The script is supposed to instantiate a new scene once the body ("Player") enters the portal. After the player has entered the new scene, the previous one is supposed to be deleted with the queue_free function.
Currently I have:
- A portal (Area3D) with the script:
extends Area3D var next_scene = preload("res://rooms/room_2.tscn") var current_scene = preload("res://rooms/room_1.tscn") func _on_body_entered(body: Node3D) -> void: if body.name == "Player": if body.in_transition == false: body.in_transition = true print("something might work") var instanced_scene = next_scene.instantiate() get_tree().root.get_node("World").add_child(instanced_scene) func _on_body_exited(body: Node3D) -> void: if body.in_transition: body.in_transition = false
- room2 (Node3D) with the script:
extends Node3D @onready var player = $Player @onready var room1 = "res://rooms/room_1.tscn" # Called when the node enters the scene tree for the first time. func _ready() -> void: player.camera.make_current()
- the World (root) node (Node3D):
extends Node3D @onready var room1 = "res://rooms/room_1.tscn" var room1_scene = preload("res://rooms/room_1.tscn") # Called when the node enters the scene tree for the first time. func _ready() -> void: if room1_scene != null and is_instance_valid(room1): #room1.queue_free() var deletion_scene = room1_scene.instantiate() deletion_scene.queue_free() print("room1 deleted")
No error appears with this version of the code but it doesn't work.