I’ve been working on a few examples for Game Analytics in Unreal4. These scripts pull data based off of specific events and writes them to a log file in your project folder
The first thing you need to do is to startup your data analytics plugin for UE4 which is off by default.
There are a variety of data packages that you can hook Unreal into, which is really valuable, but for now I’d like to read my data out to a local file. To do this, navigate to your local folder “C:\Users\UserName\Documents\Unreal Projects\ProjectName\Config” and find the file DefaultEngine.ini
Open this file in a text editor and add the following text exactly as shown below
Save the file and restart Unreal4.
There are three steps the analytics package needs to perform to operate successfully
- Starting up a session
- Recording your data
- Saving your file (ending your session)
Starting your session
To start your session, open up your level blueprint and add a Start Session from your newly available analytics package dropdown. If you can’t find it, make sure you’ve enabled your plugin. I’ve setup our script to start the session when the game begins, then display a message indicating the state change.
The second script in this picture is our End Session behavior. Whenever I’ve decided to stop recording data (typically when a user exits the game, but in this case, whenever I press Enter). I usually set up these two scripts first and leave them.
The Third script shows us our initial data collection tool Record Event with Attribute. This is currently tied to the T button, but you can use any method here to collect a single record.
you may notice there is also a record event with multiple attributes. As your data harvesting gets more complex, for instance recording the player death, position, enemy that killed them, and the enemy position, you’ll need to make more complex entries. In this case, I read in the NAME of the object being destroyed and the POSITION of the same object. It records like this
–>Data 1: Actor Name
–>Data 2: Actor Position
I’ve set up a very simple cube that can be destroyed by player bullets within the First Person Shooter example. The first script sets up the cube, the second records two types of data. The first is an example of player position recording every second recording one data type. The second example records multiple data inputs. Notice how you have to prepare your data by putting it into an array, then use the Record Event with Attributes script. Again, I also print to the screen to make sure I am recording things accurately in game.
Destroy Cube06 with Bullets
Record Data Events
And that’s it!