Hey everyone,
We’re considering upgrading our projects to the new ESM scripting system by moving away from the now deprecated ScriptType-class and using the new Script-class instead. I’ve noticed scripts can now be registered with the PlayCanvas engine by exporting them from an .mjs file:
export class FooBar extends Script { ... }
Previously we’d use pc.registerScript(scriptClass, scriptName)
to register our ScriptType-based scripts with names that use PascalCase (e.g. “PlayerController”) and sometimes with spaces and other characters (e.g. “First-Person Camera Controller”). Is there any way to use custom script names with the new ESM approach?
I’ve looked into how scripts are loaded at runtime and it doesn’t give me much hope:
It seems the script’s class name is directly converted to lowerCamelCase and used as the script’s name. This would mean all uses of our scripts in our projects will break (that’s hundreds of scripts) since their names don’t follow the lowerCamelCase format. Are there any plans to support custom script names again? We’ve relied on this feature for years and we simply can’t just go on without it as it would require manually repairing many, many entities and templates throughout our projects.
Thanks for the help.