UnrealEnginePython Tutorial
Last updated
Was this helpful?
Last updated
Was this helpful?
The following tutorial demonstrates the power of UnrealEnginePython to manipulate objects in the running game with Python, i.e. import unreal_engine
. For more tutorials on how to use UnrealEnginePython (UEPy) see their docs.
Here, we'll show how to print to the Unreal Logs, get the ego vehicle (your car), and move the ego vehicle around.
Find your sim binaries by opening up ~/Deepdrive
and sorting by date
Drill down to the Deepdrive binary
Open a terminal, drag the file into the terminal, and press enter to open the sim in the terminal and see the logs.
Once the sim is open and you see the, press M
to drive the car manually.
Within your binary folder, i.e. something like deepdrive-sim-linux-3.0.20190528000032
open your DeepDrive/Content/Scripts
in your favorite editor and create a new Python file named move_car_tutorial.py
and enter:
Now hit the backtick `
key to open the Unreal Console and enter
You should then see "hello world" printed to the logs in the terminal:
Now you know how to run Python within Unreal Engine. Let's do something more interesting!
Paste the following into move_car_tutorial.py
Now open the Unreal Console again in the simulator with `
and hit the up arrow to rerun the previous command which should be
Happy flying!!!
Often when developing a UEPy script, you won't know the exact name of the object you want to manipulate. Some general methods for introspecting the games internal state are demonstrated with the following script
Here you can see the wealth of functionality and information UnrealEnginePython provides, including the get_actor_location
and set_actor_location
methods we've just demonstrated. Imagine learning the game's state information with the input remapping trick!