Fix 'Script class can only be set together with base class name' error with .NET typed collections upon rebuild #106243
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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