Passing variables from one scene to another

Godot Version

4.2.2

Question

What’s the best and cheapest way to pass variables from one scene to another, every frame, and back again if needed?

My use case is:

In Scene 1 the player moves on a flat plane. In this scene I convert the player’s coordinates (X,Z) to latitude/longitude as a Vector2

In Scene 2 I want to access this lat/long coordinate whenever it changes, or simply every frame.

I haven’t been able to get signals to work, and singleton seems too expensive.

If you’re using C#, a static class should work.
I don’t know if GDScript has an equivalent to static classes.

I don’t see what the problem is with Singletons either. Just keep the instance in memory and use it to pass variables around.

1 Like

GDScript for now.

Thanks, I went ahead and used a singleton. I was worried it would eventually slow performance, since I will be passing other lat/long coordinates back to Scene 1.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.