how do i reference a scene while it is in another scene?

Godot Version

Godot 4

Question

I’m a Godot beginner and I am making a flappy bird game to learn godot.

And when i try to reference the game manager (that is in the main scene) in the pipe script (which is in the pipe scene) it doesn’t work

How does it work and how can I fix it?

func _on_body_entered(body: Node2D) -> void:
	%game_manager.add_score()

As there’s only one game manager, you could give it a static reference:

class_name GameManager
extends Node

static var instance

func _enter_tree() -> void:
    instance = self

...

and then use it inside your pipe script like this:

func _on_body_entered(body: Node2D) -> void:
    GameManager.instance.add_score()

You can also check how autoload nodes work in Godot.

1 Like

Thank you it helped me a lot (both)