Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SceneTree::get_singleton() is not available #1597

Open
aaronfranke opened this issue Sep 19, 2024 · 3 comments
Open

SceneTree::get_singleton() is not available #1597

aaronfranke opened this issue Sep 19, 2024 · 3 comments

Comments

@aaronfranke
Copy link
Member

Godot version

Godot 4.3-stable

godot-cpp version

master b93d6e8

System information

macOS 14.6.1 arm64

Issue description

SceneTree *scene_tree = SceneTree::get_singleton();

This code snippet compiles in engine code, but does not compile in godot-cpp:

 error: no member named 'get_singleton' in 'godot::SceneTree'
   91 |         SceneTree *scene_tree = SceneTree::get_singleton();
      |                                 ~~~~~~~~~~~^
1 error generated.

My use case is that I'm trying to connect to signals on SceneTree such as physics_frame.

It seems that most other singletons have this method in godot-cpp, it's just SceneTree where it's missing:

Screenshot 2024-09-18 at 8 30 03 PM

Steps to reproduce

Add SceneTree *scene_tree = SceneTree::get_singleton(); to a GDExtension godot-cpp project and try to compile it.

Minimal reproduction project

I'm not gonna bother including a minimal reproduction project since it's one line of code.

@AThousandShips
Copy link
Member

It isn't registered as a singleton, and isn't available in scripting as such, see scene/register_scene_types.cpp

@BenLubar
Copy link

BenLubar commented Oct 7, 2024

SceneTree is accessed in GDScript via Engine.get_main_loop().

@dsnopek
Copy link
Collaborator

dsnopek commented Oct 7, 2024

Yeah, it's a workaround, but you can get the scene tree like this:

SceneTree *scene_tree = Object::cast_to<SceneTree>(Engine::get_singleton()->get_main_loop());

We should probably generate a SceneTree::get_singleton() function that does this in godot-cpp, to make code compatible with modules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants