Skip to content

Fix 'Script class can only be set together with base class name' error with .NET typed collections upon rebuild #106243

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

Conversation

juanjp600
Copy link
Contributor

@juanjp600 juanjp600 commented May 10, 2025

Should fix #103343.

This bug was made apparent by an edge case that was not known when #98545 was made.

The .NET script-type bimap is reset every time a project is rebuilt because the assembly needs to be reloaded. This means that all the scripts need to be reloaded, and the instances of those scripts in the scene need to be refreshed so their exports are correct again.

Typed collections that contain script objects require a reference to the script to be constructed. The bug arises when exports are reconstructed before a required script is reloaded, which makes the engine unable to determine the native base class of the script type. This scenario can be forced by introducing a cyclic dependency, as I've done in the MRP attached at the bottom, although this is not the only way to cause the bug to occur.

The fix here is to populate the .NET script-type bimap and update some type info in a separate pass prior to reloading the scripts properly, so the collections can be reconstructed correctly.

MRP: DotnetScriptInitializationOrderBug.zip

@juanjp600 juanjp600 requested a review from a team as a code owner May 10, 2025 13:58
@Chaosus Chaosus added this to the 4.5 milestone May 10, 2025
Copy link
Member

@raulsntos raulsntos left a comment

Choose a reason for hiding this comment

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

Thanks, looks good to me. Tested with the MRP and works as intended.

@raulsntos raulsntos added the cherrypick:4.4 Considered for cherry-picking into a future 4.4.x release label Jun 24, 2025
@Repiteo Repiteo merged commit 26678d0 into godotengine:master Jun 24, 2025
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Jun 24, 2025

Thanks!

@juanjp600 juanjp600 deleted the dotnet-script-initialization-order-collections-bug branch June 24, 2025 18:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug cherrypick:4.4 Considered for cherry-picking into a future 4.4.x release topic:dotnet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Getting "ERROR: Script class can only be set together with base class name" after upgrading.
4 participants