Skip to content

Add SceneTree::get_singleton() - #2007

Merged
dsnopek merged 1 commit into
godotengine:masterfrom
Ijtihed:fix/scene-tree-get-singleton
Jul 27, 2026
Merged

dsnopek merged 1 commit into
godotengine:masterfrom
Ijtihed:fix/scene-tree-get-singleton

Conversation

@Ijtihed

@Ijtihed Ijtihed commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Adds a SceneTree::get_singleton() to godot-cpp which mirrors the method available to modules in Godot core. SceneTree is not a registered engine singleton so I implemented it like it was suggested in the issue (thanks to @dsnopek):

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

the declaration is injected into the generated header with a binding_generator.py specias case. I added a test method and assertion to the integration test.

Fixes #1597

AI disclosure

I used claude to brainstorm then make sure I didn't miss any blind spots/repo conventions. All code was written and reviewed by me.

@Ijtihed
Ijtihed requested a review from a team as a code owner June 24, 2026 05:05
@Ijtihed
Ijtihed force-pushed the fix/scene-tree-get-singleton branch from fa02843 to 7afa095 Compare June 27, 2026 14:04
@Ijtihed

Ijtihed commented Jun 27, 2026

Copy link
Copy Markdown
Contributor Author

It failed CI and now it shouldn't anymore :)

@dsnopek dsnopek left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

At a high-level, I think this is the right way to add this method. But I'm not sure about the effect this has on build profiles. Like, this is essentially making it so that all build profiles will now need "Engine" and "SceneTree" in them, affecting all users that have build profiles.

So, I think we either need to (a) accept that and have this listed as always included in parse_build_profile() (so users at least don't need to add them manually) or (b) use #ifdefs to only include this implementation in low_level.cpp if SceneTree and Engine are available

@dsnopek dsnopek added the enhancement This is an enhancement on the current functionality label Jul 4, 2026
@dsnopek dsnopek added this to the 10.x milestone Jul 4, 2026
@Ijtihed

Ijtihed commented Jul 5, 2026

Copy link
Copy Markdown
Contributor Author

Thanks!

At a high-level, I think this is the right way to add this method. But I'm not sure about the effect this has on build profiles. Like, this is essentially making it so that all build profiles will now need "Engine" and "SceneTree" in them, affecting all users that have build profiles.

So, I think we either need to (a) accept that and have this listed as always included in parse_build_profile() (so users at least don't need to add them manually) or (b) use #ifdefs to only include this implementation in low_level.cpp if SceneTree and Engine are available

I think b is probably best. So I'd #ifdef-guard the impl and declaration in low_level.cpp and leave parse_build_profile() alone. Does that seem good?

@dsnopek

dsnopek commented Jul 25, 2026

Copy link
Copy Markdown
Collaborator

So I'd #ifdef-guard the impl and declaration in low_level.cpp and leave parse_build_profile() alone. Does that seem good?

That sounds good to me!

@Ijtihed
Ijtihed force-pushed the fix/scene-tree-get-singleton branch from 7afa095 to 27a7acc Compare July 26, 2026 06:01
@Ijtihed

Ijtihed commented Jul 26, 2026

Copy link
Copy Markdown
Contributor Author

So I'd #ifdef-guard the impl and declaration in low_level.cpp and leave parse_build_profile() alone. Does that seem good?

That sounds good to me!

Cool, done

@dsnopek dsnopek left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

The code looks good to me. Let's see what CI says

@Ijtihed

Ijtihed commented Jul 26, 2026

Copy link
Copy Markdown
Contributor Author

Thanks!

The code looks good to me. Let's see what CI says

Seems to be alright

@dsnopek
dsnopek merged commit eb006b6 into godotengine:master Jul 27, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement This is an enhancement on the current functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SceneTree::get_singleton() is not available

2 participants