Skip to content

Update GDScriptLanguage::globals when a GDExtension is loaded in exported builds#105319

Open
ze2j wants to merge 1 commit intogodotengine:masterfrom
ze2j:fix_gdscript_bug_with_gdextension_types
Open

Update GDScriptLanguage::globals when a GDExtension is loaded in exported builds#105319
ze2j wants to merge 1 commit intogodotengine:masterfrom
ze2j:fix_gdscript_bug_with_gdextension_types

Conversation

@ze2j
Copy link
Contributor

@ze2j ze2j commented Apr 12, 2025

Fix 104056

The root cause of the issue is that the GDScriptLanguage::globals is not updated when a new GDExtension is loaded in an exported game. This leads to a GDScript compilation failure when the types defined by the GDExtension are used explicitly in .gd scripts loaded from a pck file (such as a mod).

The logic to handle this already exists (added in 93972) but is currently enabled only on editor builds. My proposed fix is to remove that constraint so it also applies to exported builds. I haven’t noticed any side effects, but I’m not very familiar with this part of the engine, so let me know if this isn’t the right approach.

@ze2j ze2j requested review from a team as code owners April 12, 2025 16:16
@ze2j
Copy link
Contributor Author

ze2j commented Apr 12, 2025

The GDExtensionManager documentation needs an update as with this PR the signals extension_loaded and extension_unloading are now emitted in exported builds too. I'll fix this tomorrow.

EDIT: documentation updated

@ze2j ze2j marked this pull request as draft April 12, 2025 16:46
@ze2j ze2j force-pushed the fix_gdscript_bug_with_gdextension_types branch from b18c6a7 to 7af58c0 Compare April 13, 2025 08:06
@ze2j ze2j marked this pull request as ready for review April 13, 2025 09:21
@ze2j ze2j requested a review from a team as a code owner April 13, 2025 09:21
@AThousandShips AThousandShips added bug topic:gdscript cherrypick:4.3 Considered for cherry-picking into a future 4.3.x release cherrypick:4.4 Considered for cherry-picking into a future 4.4.x release labels Apr 14, 2025
@AThousandShips AThousandShips added this to the 4.5 milestone Apr 14, 2025
@ze2j ze2j changed the title Fix GDScript compilation error with GDExtension types when loaded from a pck Update GDScriptLanguage::globals when a GDExtension is loaded in exported builds Apr 18, 2025
@Repiteo Repiteo added the cherrypick:4.5 Considered for cherry-picking into a future 4.5.x release label Sep 18, 2025
@Repiteo Repiteo modified the milestones: 4.5, 4.x Sep 18, 2025
Comment on lines +2282 to +2283
GDExtensionManager::get_singleton()->connect("extension_loaded", callable_mp(this, &GDScriptLanguage::_extension_loaded));
GDExtensionManager::get_singleton()->connect("extension_unloading", callable_mp(this, &GDScriptLanguage::_extension_unloading));
Copy link
Contributor

Choose a reason for hiding this comment

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

These signals are best disconnected in GDScriptLanguage::finish() to prevent spam in unit tests (godot --test).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! I added the disconnections as requested.

@HolonProduction
Copy link
Member

Just to clearify: In exported games are extensions expected to be unloadable?

@ze2j ze2j force-pushed the fix_gdscript_bug_with_gdextension_types branch from 7af58c0 to f9ced2b Compare December 20, 2025 17:09
@ze2j
Copy link
Contributor Author

ze2j commented Dec 20, 2025

@HolonProduction I don't know in the general case, but in this particular case nothing prevents it AFAIK. TBH I never tried to unload a GDExtension from an exported game. This may deserve some additional tests to ensure it works, otherwise I would have to revert the unloading part of this PR.

Copy link
Contributor

@dsnopek dsnopek left a comment

Choose a reason for hiding this comment

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

The GDExtension parts of this seem fine to me. I can't speak to the GDScript parts

@HolonProduction
Copy link
Member

I still think it's important to know whether extension unloading is supported. globals is not really meant for globals which can be removed. If this is a feature we should use named_globals. See also #111506

@dsnopek
Copy link
Contributor

dsnopek commented Jan 13, 2026

I still think it's important to know whether extension unloading is supported.

Loading and unloading extensions at runtime should work. And, in fact, is a requirement for implementing #97991, however, that doesn't need to work in release builds. I would expect that needing to unload a GDExtension in a release build to be very uncommon.

@HolonProduction
Copy link
Member

Then this should use named globals IMO.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug cherrypick:4.3 Considered for cherry-picking into a future 4.3.x release cherrypick:4.4 Considered for cherry-picking into a future 4.4.x release cherrypick:4.5 Considered for cherry-picking into a future 4.5.x release topic:gdscript

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SCRIPT ERROR: Compile Error: GDScript bug (please report): Native class "GDExample" not found.

6 participants