Use VsCode to debug PuerTs of UE5
1. Download the demo project for testing
The steps of configuring PuerTs are not repeated here.
2. Preparation
2.1 Opening a project
Normally, you can see the following screen when you open the project directly
If you click Run directly, you can find that the Output Log window below has started to print many cases.
It is because the project executes QuickStart.ts by default.
2.2 Open TsGameInstance.cpp
3. Add VsCode breakpoint
3.1 Find QuickStart.ts in VsCode, just break a point
(Here we take L17 as an example)
4. Modify the virtual machine port (8889)
(If you don’t know the purpose of the virtual machine, you can check ZombieYang’s tweet )
Go back to TsGameInstance.cpp
and uncomment
The picture is too long. The current code is as follows:
void UTsGameInstance::OnStart()
{
//GameScript = MakeShared<puerts::FJsEnv>();
GameScript = MakeShared<puerts::FJsEnv>(std::make_unique<puerts::DefaultJSModuleLoader>(TEXT("JavaScript")), std::make_shared<puerts::FDefaultLogger>(), 8889);
GameScript->WaitDebugger();
TArray<TPair<FString, UObject*>> Arguments;
Arguments.Add(TPair<FString, UObject*>(TEXT("GameInstance"), this));
GameScript->Start("QuickStart", Arguments);
}
Pay attention to the modified code. I have changed the port to " 8889 "
and opened WaitDebugger() at the same time, the purpose is for the Client to wait for the V8 virtual machine (the relationship between the Client and the V8 virtual machine can also be viewed on ZombieYang's tweet )
5. Add VsCode configuration
5.1 Open the Debug configuration of VsCode
5.2 Select Node.js: Attach
5.3 Change the port to (8889)
6. Start Debugging
6.1 Start VsCode standby
①First select the Debug configuration added in 5.2
②Click the green triangle on the left
to see the following schematic box
6.2 Start the project of 2.1
Not surprisingly, it has been successfully interrupted.
7. Enjoy Debug~
reference:
[UE] VSCode 1.64.2 cannot breakpoint debug TS
Puerts Inspector Guide (1) Debugging Javascript in UE4 and Unity