Previously, we saw how to run Python inside of Unreal. Now it’s time to learn about Python itself.
We won’t write any Python code related to UE, just basic Python.
Table of contents
Python is huge and versatile. On top of that, learning rules is a boring process and it’s just not possible to learn Python by the book for many people, including me.
Instead of throwing out the rules of Python, I propose you a giant Python syntax cheat sheet that you can keep around and come back to any time you want.
However, if you want the rules, python is very well documented so you can easily find tutorials and video tutorials online. Just make sure to learn about Python 3 and not Python 2 (although it’s not a big problem, they are really close). Here is an example of written rules of Python.
This is Python scripts with comments that explain how to write Python.
Download the project files at the beginning of this training, and from UE, open the files named cheat_sheet
in the folder Content/Python/Help/Basics
. It should open them in VS Code.
Use them as reference to complete the exercises at the end of this chapter.
To run a cheat sheet, right click on it from UE and press Run
. It should print stuff in the Output Log.
Before anything else, you should know about Python errors.
When you run some Python code and something goes wrong, it will throw an error.
For example if you run:
primt(12)
It will output:
LogPython: Error: Traceback (most recent call last):
LogPython: Error: File "<string>", line 1, in <module>
LogPython: Error: NameError: name 'primt' is not defined
Because primt()
is the wrong name and it doesn't exists. It should be print()
.