Organizing complex FMOD Events with Data Tables in Unreal Engine 4

Similar to Data Assets, we can use Data Tables to organize complex FMOD Events in clear and comprehensible way. A Data Table is an asset that contains a collection of rows. Like in a spreadsheet, the rows all have shared columns. In this tutorial we will create a custom FMOD Studio script that will export FMOD Events with Parameter name information to a .csv file. We will use this file to automatically create a Data Table in Unreal Engine 4

Automatically export .csv tables with JavaScript Scripting in FMOD Studio

We have the possibility to automate the table creation step by writing JavaScript code that can be executed directly in FMOD Studio. To write custom FMOD Studio scripts, we create a new Scripts folder in the root directory of the FMOD Studio project and create a new script named DataTable.js for example. Insert the following code into the script:

studio.menu.addMenuItem({
	name: "UE4\\DataTable",
	isEnabled: function () {
		var events = studio.window.browserSelection();
		return events
	},

	execute: function () {
		var events = studio.window.browserSelection();
		var parameterNumber = studio.system.getNumber("Parameter Number", "0");
		var FinalData = "Name" + "," + "FMODEvent";

		for (x = 0; x < parameterNumber; x++) {
			FinalData += "," + "Parameter" + " " +  (x+1);
		}

		for (x = 0; x < events.length; x++) {
			var quotes = String.fromCharCode(34);
			var quote = String.fromCharCode(39);
			var event = events[x].getPath();
			var eventName = events[x].name;
			var parameters = events[x].getParameterPresets();
			var parameterNames = "";

			for (y = 0; y < parameters.length; y++) {
				parameterNames += "," + parameters[y].presetOwner.name;
			}

			event = event.replace('event:', quotes + 'FMODEvent' + quote + '/Game/FMOD/Events');
			event += "." + eventName + quote + quotes;
			FinalData += "\r\n" + eventName + "," + event + parameterNames;
		}

        var fileName = studio.system.getText("File Name", "NewFile");
        var projectPath = studio.project.filePath;
        projectPath = projectPath.substr(0, projectPath.lastIndexOf("/"));
        var filePath = projectPath + "/" + fileName + ".csv";
		var file = studio.system.getFile(filePath);

		file.open(studio.system.openMode.WriteOnly);
		file.writeText(FinalData);
		file.close();
	}
});

Now open FMOD Studio. Select a complex Event with multiple parameters:

FMOD Event with multiple Parameters
FMOD Event with multiple Parameters

Locate and click on the Scripts->UE4->DataTable menu entry. Insert the desired number of parameters that should be added to the table:

Selecting the number of parameters to be added to the Data Table
Selecting the number of parameters to be added to the Data Table

Give the file a new name and click on OK. You’ll be able to find the new created .csv file in the root directory of the FMOD Studio Project. The file content will look similar to this file:

Name,FMODEvent,Parameter 1,Parameter 2,Parameter 3,Parameter 4,Parameter 5
Overworld-Combat-Hard,"FMODEvent'/Game/FMOD/Events/Music/Overworld-Combat-Hard.Overworld-Combat-Hard'",PlayerHP,PlayerHPInstant,HealMiniGame,FleeMiniGame,EnemiesDead

Data Table .csv import and creation in Unreal Engine 4

To create a Data Table we need to create a Struct first. In Unreal Engine, create a new Structure by right-clicking on the Content Browser and choosing Blueprints->Structure. I will name the Struct AudioTableStructure. Create a few variables and choose FMODEvent for the first variable type and Name for the rest of the variables. In my case, it looks like this:

A Structure in Unreal Engine 4
A Structure in Unreal Engine 4

It’s important to make sure that the variable names are the same as in the .csv file. If you wish to change the variable names, modify the .js script to reflect that. Now you can drag-and-drop the .csv file we created in FMOD Studio into the Content Browser. Unreal will now prompt you to Choose a DataTable Row Type, just as in the following screenshot:

Data Table Options
Data Table Options

Select the Structure we created earlier and click on OK. A new Data Table will be created with automatically populated rows corresponding to the fields generated in the .csv file:

Automatically populated Data Table in Unreal Engine 4
Automatically populated Data Table in Unreal Engine 4

In a Blueprint, we can finally get the Data Table Row information by using the Get Data Table Row node in combination with the Break (Structure) node:

Example Blueprint with Data Table
Example Blueprint with Data Table

↑ To the Top