Skip to content

How to debug your game net code

Andrea Catania edited this page Dec 6, 2022 · 11 revisions

To debug your game net code, you can use the built-in debugger, that will allow you to fetch node data per each frame.

ezgif com-gif-maker(1)

Use it in three steps.

1. Enable the debugger

As the first thing you want to enable the SceneSynchronizerDebugger as by default it's disabled; you can enable it by set the godot project settings property NetworkSynchronizer/debugger/dump_enabled to true.

2. Enable the debugger

By default, the debugger fetches a bunch of useful information from all the networked nodes; however, if you want to also fetch information from some other nodes you can add the class name to the project settings NetworkSynchronizer/debugger/dump_classes: the debugger will fetch information from any node that inherits the classes you add to that list.

3. Just reproduce the behaviour to debug

Now that the debugger is enabled, all you have to do is to open the Client/Server instances and reproduce the behaviour you want to analyze. Once you have reproduced the issue, you can simply close the instances.

Now navigate to your godot/bin directory to find a newly created directory: net-sync-debugs/dump. Navigate into it.

There you will find the debugger.py (a python UI to help you navigate the debugged frames).

Launch it using the command python debugger.py

Note, to use the UI you must install:

  • Install python
  • Install pip
  • Install PySimpleGUI: pip install pysymplegui
  • Install Tkinter:
    1. Install Tkinter app:
      • Fedora: sudo dnf install python3-tkinter
      • Ubuntu: sudo apt-get install python3-tk
    2. Install python library: pip install tk

The UI

The UI is composed by 5 panels.

Screenshot from 2022-12-05 14-59-06

  1. Frame list: Show all the frames + a small summary.
  2. Node list: Shows all the nodes captured in that frame.
  3. Error detection area: The debugger has the ability to detects some malfunctioning; In that case, an error about it will appear there.
  4. Node dump: This area shows the node variable dumping.
  5. Log output: Here you will find the log output generated by the selected node on the given frame. (Here you can find a bunch of messages, warnings, errors, but also the data buffer write and read).

The Frame list and the Node filtering

You can use the first panel to navigate the frames (You can use the arrows too). The next thing you want to do is to select the nodes to debug (using the 2nd panel); essentially here you are filtering the nodes.

The nodes status

The 4th panel shows the nodes status: essentially the debugger dumps the node variables before starting the frame and after.

Screenshot from 2022-12-06 09-10-33

The 4th panel shows the nodes' status: essentially, the debugger dumps the node variables before starting the frame and after.

🔄 This symbol is used to signal that the variable is tracked by the NetworkSynchronizer.

⚠️ This symbol is used to signal that the value is different between server and client.

The log

The log view is really interesting. By organizing the log per node, it tells a lot of useful information about the processing, on both serer and client.

For example, in this view you can compare the data written on the DataBuffer on client with the one read on the server, and figure out why the node de-sync.

Screenshot from 2022-12-06 09-41-59

The API

You can actively interact with the debugger, even from GDScript. Here is a list of API to write messages; that can be used to mark important information about the game play, that will give even more insight about the processing.

void debug_print(Node *p_node, const String &p_message, bool p_silent = false);
void debug_warning(Node *p_node, const String &p_message, bool p_silent = false);
void debug_error(Node *p_node, const String &p_message, bool p_silent = false);
Clone this wiki locally