[FIX] Fix ScriptComponent clone not handling awaiting scripts#8264
[FIX] Fix ScriptComponent clone not handling awaiting scripts#8264willeastcott wants to merge 1 commit intomainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug in the ScriptComponentSystem.cloneComponent method where scripts in an "awaiting" state (scripts that are referenced but not yet registered) were not being properly included in the cloned entity's script order due to incorrectly accessing properties on a string key instead of the script entry object.
- Fixed the
for...inloop to correctly retrieve and check the script entry object instead of checking properties on the string key - Now properly handles awaiting scripts by accessing
scriptEntry.awaitingandscriptEntry.indinstead ofkey.awaitingandkey.ind
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const scriptEntry = entity.script._scriptsIndex[key]; | ||
| if (scriptEntry.awaiting) { | ||
| order.splice(scriptEntry.ind, 0, key); |
There was a problem hiding this comment.
The fix correctly handles awaiting scripts during cloning, but there is no test coverage for this scenario. Consider adding a test that verifies cloning an entity with a ScriptComponent that has scripts in the "awaiting" state (i.e., scripts that are referenced but not yet registered). This would ensure the fix works as intended and prevent future regressions.
Description
When cloning an entity with a ScriptComponent, scripts in an "awaiting" state were not being properly included in the clone's script order.
Bug
The
cloneComponentmethod was iterating over_scriptsIndexusingfor...in, but incorrectly checking properties on the string key instead of the script entry object:Since
keyis a string (the property name),key.awaitingwas alwaysundefined(falsy), making this code block effectively dead code.Fix
Access the actual script entry object stored at that key:
Fixes #2796
Checklist