Improbable Icon

Debugging All Code in Unreal Game

unreal
v12

#1

I’m looking for information on how to debug both the player and the managed workers on an Unreal project. In a previous message it was suggested to change the ClientWorkerName to UnrealWorker instead of UnrealClient, but then the player never spawns. So how can I spawn the player, but then be able to step through code in both the C++ and Blueprint side of things for either a managed worker or the player?

Thanks,
eric


#3

Hello @chosenofset !

So from the UnrealStarterProject, GameMode can override the WorkerType using this code :

 if (!WorkerTypeOverride.IsEmpty())
 {
        workerConfig.SpatialOSApplication.WorkerPlatform = WorkerTypeOverride;
 }

But if you want to make this system more flexible you can add a custom argument to the command line when you execute your standalone client, like this :

 FString CommandLineWorkerType;
  if (FParse::Value(FCommandLine::Get(), TEXT("OverrideWorkerType="), CommandLineWorkerType))
  {
      workerConfig.SpatialOSApplication.WorkerPlatform = CommandLineWorkerType;
  } 
 else if (!WorkerTypeOverride.IsEmpty())
 {
 	workerConfig.SpatialOSApplication.WorkerPlatform = WorkerTypeOverride;
 }

Finally create two bat files to execute a worker as client or not, here my StartClient.bat :
(remplace <PROJECT_NAME> by the name of your .uproject file)

 @echo off
 start "UnrealClient" "%UNREAL_HOME%/Engine/Binaries/Win64/UE4Editor-Cmd.exe" "%~dp0/workers/unreal/Game/<PROJECT_NAME>.uproject" -game -log -ResX=1280 -ResY=960 -OverrideWorkerType="UnrealClient" -WINDOWED
 exit

And for StartWorker.bat simply remplace “UnrealClient” by “UnrealWorker”

NOTE : Don’t use the WorkerType key since it’s already used by SpatialOS, that’s why I use OverrideWorkerType.

I hope it solve your issue ! :smile:


#4

@Jackblue,

Ok, to make sure I’m understanding what you are explaining. I start up my local spatial server, it will load up the snapshot and create the managed worker. I can then run the StartWorker.bat and I should be able to breakpoint/step through/otherwise see what the worker is doing. Then I can run StartWorker again as UnrealClient and see the player and get all of the client side stuff to breakpoint/step through/otherwise see. Or do I not have a managed worker and the UnrealWorker is starting that manually?

Thanks


#5

The method I describe above, is to create a managed worker or a client in more flexible way.

Normally if debug files are present, you should be able to attach a debugger to your client/worker process and debug your code yup :smile:


#6

Attaching a debugger to the running process would work for the C++ side of things, but not for the blueprint unless Unreal has a way of attaching an editor to a running process that I don’t know about.

Essentially the issue I’m running into is that when the client closes, the player entity that was spawned doesn’t ever get removed from Spatial. If you connect again without restarting the Spatial server, you will see your old player still in the level just sitting there. I have code in my Blueprints that is supposed to remove the player if nothing is controlling it anymore (heartbeat based like in the examples) but it looks like it isn’t getting called, and I’m not sure how I can go about debugging that to figure out why it isn’t getting called.

I’ve seen reference in old messages to an Iteration/Debugging document for Unreal but it looks like that doesn’t exist anymore. It would be great to have something like that back for the current version. Something that gives some best practises/hints at debugging and finding the cause of errors.


#7

You can debug BP properties using this VS extension :

Also you can use logs from managed worker (MyProject/logs) or from your client worker (MyProject\workers\unreal\Game\Saved\Logs) to track your issue using logs.