Changing scenes🤷‍♂️

Godot Version

4.7.1

Question

Hello. When I am trying to change scenes from scene “A” to “B” it works but when I wanna go back from “B” to “A” it failes, setting “destination” to null. When main scene is set to “B” the same problem occurs from scene “A”. Any idea why is it happenin? Been fryin my brain on this for 2 days.

There is portal script:

extends Node3D

@export var destination: PackedScene
@onready var portal = $Pedastal/PortalOpen
enum states {open,closed}
var state = states.closed

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
	portal.visible = false
	portal.monitoring = false
	state = states.closed

func open_portal():
	portal.visible = true
	portal.monitoring = true
	state = states.open
	
func close_portal():
	portal.visible = false
	portal.monitoring = false
	state = states.closed

func _on_portal_open_body_entered(body: Node3D) -> void:
	if body.is_in_group("player"):
		call_deferred("_change_scene")

func _change_scene() -> void:
	print("DESTINATION: ", destination)
	print("DESTINATION PATH: ", destination.resource_path if destination else "NULL")
	get_tree().change_scene_to_packed(destination)

I would suggest to check both scenes if you assigned correctly

This is a known issue with the circular references.

There is a proposal to have it handled properly:

Use SceneTree::change_scene_to_file() instead

What do u mean? It wouldnt work from B to A in the first place if it was assigned wrong no?

Yea circular dependency it was :slight_smile:

I mean it wasn’t obvious to me sorry, it’s always easier see it then read it.

But you got solution, so that’s all it matters.