+1 vote

I have a script to changes the scene when a button is clicked. Because the scene that holds this script is preloading a scene that preloads the first scene, I get this error:

E 0:00:01.795   load: Resource: 'res://scenes/CityStreet.tscn' is already being loaded. Cyclic reference?

Is there a way to be able to reference scenes to each other without creating a cyclic reference?

The script in question:

extends TextureButton

export var next_scene_path: PackedScene

func _on_pressed():
    print("button pressed")

func _get_configuration_warning() -> String:
    return "No scene loaded" if not next_scene_path else ""

func transition() -> void:
    var next_scene = next_scene_path.instance()
    get_tree().get_root().call_deferred("add_child", next_scene)
in Engine by (13 points)

1 Answer

0 votes

If you have two scenes referencing to each other with export var scene: PackedScene, you will have a cyclic reference error.

A solution is to use export (String, FILE) var scene_path.

To keep it handy, I use a custom class to store the scene path.

extends Resource
class_name ScenePath

export (String, FILE) var value
by (320 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.