Introduction
As the project grows in scale, I increasingly feel that the Lua scripts are getting out of control, so I’m trying out a TypeScript scripting solution.
So I looked into how PuerTS works.
From my experience, PuerTS is indeed significantly harder to get started with than UnLua. On one hand, the TypeScript ecosystem is inherently more complex than Lua; on the other hand, PuerTS offers plenty of flexibility, and having so many choices actually makes it less clear how to proceed in real projects.
Q&A
Is there a best practice?
Officially there are no more detailed examples; for now you can mainly refer to the puerts_unreal_demo project to get a sense of the author’s design.
From various forums and shared articles, it seems the official stance is not very fond of the inherit engine class feature, which leans toward the UnLua approach.
Instead, the official recommendation is to start the virtual machine yourself and implement a TypeScript-centric Gameplay framework tailored to your project’s needs.
So for developers used to UnLua’s approach of declaring a module in a Blueprint to bind a script, switching to PuerTS may feel uncomfortable, and you’ll need to adjust your mindset according to your project’s requirements,
Referring to the idea in Github Discussions 1214, you can actually implement a set of automatic binding similar to UnLua, but you do lose some of TypeScript’s type-checking capabilities, so you may still need to pair it with mechanisms like automatic generation for better maintainability.
Based on some problems I encountered in actual use, I summarized a set of best practices: Best Practices for PuerTS in Unreal Engine (UE5)
After mixin, can you call the overridden function?
No.
See the author’s reply: https://github.com/Tencent/puerts/issues/1778
And for the inherit-engine-class mode, the generated Blueprint is not recommended to be modified (it may be overwritten), so it doesn’t apply to this case either.
Extension Plugin
Following the UnLua approach, I wrote a plugin that automatically binds JavaScript classes.
You can refer to: BoilTask/PuertsAutoMixin