fix(scripts): register nameless scripts under their verbatim class name#8844
Merged
Conversation
#8831 (2.19.3) changed the name a script is registered under when no explicit name is passed to `registerScript(Class)` - from the verbatim class name (e.g. `PlayerController`) to the lowerCamelCase form (`playerController`). Projects that register ES6 classes this way and reference them by their class name then failed to resolve the script, so it never attached. Restore the pre-2.19.3 behaviour: `registerScript` falls back to the verbatim class name (still honouring an explicit name, an own `__name`, or an own `scriptName`). Resolution stays own-property only, so #8831's subclass-collision and ESM `scriptName`-field fixes are preserved. `ScriptComponent.create`, `ScriptRegistry.add` and the asset loader keep using the lowerCamelCase `getScriptRegistryName`, so the editor and asset pipeline (which always pass an explicit name) are unaffected - the change is scoped to code-driven nameless `registerScript(Class)` calls. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a regression introduced in 2.19.3 where pc.registerScript(SomeClass) (with no explicit name) no longer allowed scripts to be referenced/attached by their verbatim ES6 class name, causing script attachment to silently fail in class-name–based projects.
Changes:
- Updates
registerScriptto fall back to the verbatim class name (own__name→ ownscriptName→ verbatim class name) instead of the lowerCamelCase registry fallback. - Adjusts existing tests to assert verbatim-name registration for nameless
registerScriptusage. - Adds a regression test ensuring
entity.script.create('ClassName')attaches correctly after namelessregisterScript(ClassName).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/framework/script/script-create.js |
Restores verbatim class-name fallback for nameless registerScript while preserving own-property name resolution. |
test/framework/script/script-registry.test.mjs |
Updates expectations and adds coverage for class-name attachment after nameless registration. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
mvaligursky
added a commit
that referenced
this pull request
Jun 4, 2026
…me (#8844) #8831 (2.19.3) changed the name a script is registered under when no explicit name is passed to `registerScript(Class)` - from the verbatim class name (e.g. `PlayerController`) to the lowerCamelCase form (`playerController`). Projects that register ES6 classes this way and reference them by their class name then failed to resolve the script, so it never attached. Restore the pre-2.19.3 behaviour: `registerScript` falls back to the verbatim class name (still honouring an explicit name, an own `__name`, or an own `scriptName`). Resolution stays own-property only, so #8831's subclass-collision and ESM `scriptName`-field fixes are preserved. `ScriptComponent.create`, `ScriptRegistry.add` and the asset loader keep using the lowerCamelCase `getScriptRegistryName`, so the editor and asset pipeline (which always pass an explicit name) are unaffected - the change is scoped to code-driven nameless `registerScript(Class)` calls. Co-authored-by: Martin Valigursky <mvaligursky@snapchat.com> Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Since 2.19.3, registering an ES6 script class without an explicit name and referencing it by the class name stopped working — the script silently fails to attach. Reported by a user with "hundreds of scripts" extending
pc.ScriptTypeand registered viapc.registerScript(Class).Root cause
#8831 changed the name
registerScript/createScriptderive when no explicit name is given:The registry is keyed by that name, so an entity referencing the script as
PlayerControllerno longer resolves it. Passing an explicit name works, but that's painful across hundreds of scripts.Fix
Restore the verbatim class-name fallback in
registerScriptonly:static scriptNameclass-field case and the subclass-name-collision case.registerScript.ScriptComponent.create,ScriptRegistry.addand the asset loader still use the lowerCamelCasegetScriptRegistryName. The editor and asset pipeline always pass an explicit name, so they're unaffected — only code-driven namelessregisterScript(Class)changes (the regressed path).This was chosen over a dual-name alias (previous draft, #8840) to avoid the long-term maintenance cost and edge cases of registering each script under two names.
Note on
create(Class)create()is unchanged. For the register-then-reference flow it stays consistent:registerScript(Class)sets__nameto the verbatim name, andcreate()reuses an existing own__namerather than recomputing. lowerCamelCase derivation increate(Class)only applies to a class that was never registered — long-standing behavior.Tests
registerScript(class PlayerController)→entity.script.create('PlayerController')attaches the instance.🤖 Generated with Claude Code