Note: For this demonstration, we are using the 5.1 version of Unreal Engine, which can be downloaded from the Epic Games launcher. Newer or older versions may not work exactly as described.
Once the download is complete, open the project by launching Unreal Engine 5.1 from the launcher -> select recent projects -> browse to the download location of StackOBot -> click open.
You can play the game by pressing the "Play" button. Give the game a try!
Step 2 - Integrating GameDriver with the project.
Download and import the GameDriver plugin into the project by following the installation instructions.
Step 3 - Creating your first automated test
So our goal here will be demonstrate using GameDriver to automate certain tasks in the game like solving certain puzzles.
First task is to move the player to a switch to turn on a fan.
Locate the switch in the Outliner, find the HPath and plug it into a GetObjectPosition() api call as seen below to grab the position of the switch. Then we use a CallMethod() api call to Set the actor location to the switch location to move the player to it.
//Save the position of the switch. Vector3 switchPos = api.GetObjectPosition("/*[@name = 'BP_PressurePlate_C_UAID_B42E9936F5429ADA00_2086838180']"); //Move the bot(player) to the switch. api.CallMethod("/*[@name = 'BP_Bot_C_0']", "K2_SetActorLocation", new object[] { switchPos });
Now we press 'F' key using a KeyPress() api call, to disable the current bot on the switch and print a new one, so the switch remains active.
//Print a new Bot and assume control api.KeyPress(new KeyCode[] { KeyCode.F }, 1); //Wait for 1 sec api.Wait(1000);
Now we find the position of the fan beside the switch, which should be on now, and move the new bot to it.
//Save the position of the fan. Vector3 fanPos = api.GetObjectPosition("/*[@name = 'BP_Fan_C_UAID_B42E9936F5429ADA00_2086843187'] "); //Move the bot(player) to the fan. api.CallMethod("/*[@name = 'BP_Bot_C_1']", "K2_SetActorLocation", new object[] { fanPos });
These next two lines Asserts that the player has indeed been launched up into the air by the fan by comparing the z coordinates and then presses the 'F' key again to deactivate and print a new bot.
//Check if Fan launched the Player upwards Assert.IsTrue((api.GetObjectPosition("/*[@name = 'BP_Bot_C_1']").z > api.GetObjectPosition("/*[@name = 'BP_Bot_C_0']").z), "Fan did not activate"); //Print a new Bot and assume control api.KeyPress(new KeyCode[] { KeyCode.F }, 5);
Once you have given it a go you probably have more questions about what else can be done with GameDriver besides just teleporting the player around.
This next part of the Tutorial will go in depth covering various aspects of GameDriver and some tools that come packaged in.