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
import jsonfrom api_methods import Apiapi = Api()ego = api.get_ego_agent()location = ego.get_actor_location()ego.set_actor_location(location.x, location.y, location.z + 1e4) # +100m
Now open the Unreal Console again in the simulator with
` and hit the up arrow to rerun the previous command which should be
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
import jsonfrom api_methods import Api, best_effort_serializeapi = Api()ego = api.get_ego_agent()print('Methods -------------------------------')for m in dir(ego):print(m)print('Properties --------------------------- ')print(json.dumps(best_effort_serialize(ego, levels=5), indent=2))
Here you can see the wealth of functionality and information UnrealEnginePython provides, including the
set_actor_location methods we've just demonstrated. Imagine learning the game's state information with the input remapping trick!