Registering Messages
The Tracking System
is a special subsystem that can be used to keep track of object data over time and will be able to export that data to a CSV table. Objects, such as messages and components, can be registered to this system, which will be stored in a database locally at a specific frequency, before being outputted to a CSV table. The messages should be configured on the Begin Play event, after the Configure UI
function in a new function called Register Messages
.
The Track Object
function should be added for the battery’s Out_BatteryMsg
and the power sink object.
NOTE
There are some properties on objects that are ‘Advanced’ properties. These can be tracked by enabling the
Include Advanced
Boolean on the function.
Exporting Messages
When the simulation has ended, or when the user is required to fetch the data back from the message writer, the data must be exported to a CSV file or a directory. This can be done using the export functions on the message writer. In this example, the messages should output their data when the user ends the level. This will execute the Event End Play
. Similar to the tick and begin events, this can be added to the level blueprint and code can be executed.
When this event is called, the messages should be exported to the appropriate directory. This is done by calling the Export to CSV
function for each object.
Each object will need to be added to the Object
parameter. The Path
will be the full path to the folder, including the extension, for the CSV file to save. The Get Downloads Directory
and Append
functions can be used to help out with finding a valid file path.
WARNING
For CSV exporting it is common to use a different delimiter than the conventional comma. This is because JSON data may be present within the messages (depending on the type) and may make the columns invalid if the data includes commas. A pipe ( | ) character is more appropriate in this case.
Viewing Data
Once the simulation is completed, the data will be outputted to a CSV file within the directory provided for each message. This tutorial is now complete and the data from the power network can be extracted and stored in a CSV file for analysis.
NOTE
To add the units to the columns, select the
Include Units
variable on the CSV file export function.