Coding conventions for Unreal Engine 4 for C++, Blueprint and Python
Home / Python
Our rules for Python code in Unreal Engine are fairly straight-forward: Stick to PEP 8 and you’re good.
Depending on how much Python code you write and how runtime-critical it is you may want to extend those rules for certain projects, but even then I would discourage coming up with your own rules and instead use the Google Python Style Guide instead. It’s more verbose than PEP 8 and contains more guidelines on how to write and document code.
I don’t want to copy-paste big parts of either those conventions here and reccommend you pick either one of them and stick with it. Nevertheless, here is a bullet point list of a few rules that are often ignored by newcomers to Python, especially in an Unreal context where they are sometimes at odds with the C++ style guide.
Refer to this table for naming (copied from the Google Python Style Guide based on Guido’s Recommendations)
Type | Public | Internal |
---|---|---|
Packages | lower_with_under | |
Modules | lower_with_under | _lower_with_under |
Classes | CapWords | _CapWords |
Exceptions | CapWords | |
Functions | lower_with_under() | _lower_with_under() |
Global/Class Constants | CAPS_WITH_UNDER | _CAPS_WITH_UNDER |
Global/Class Variables | lower_with_under | _lower_with_under |
Instance Variables | lower_with_under | _lower_with_under (protected) |
Method Names | lower_with_under() | _lower_with_under() (protected) |
Function/Method Parameters | lower_with_under | |
Local Variables | lower_with_under |
I know, these rules conflict with the typical UE4 naming conventions, but this is Python code after all. UE4 exports types in CapWords and functions as lower_with_under too.
my_module.py
Module execution code
Should be an equivalent of the following in most cases:
if __name__ == '__main__':
main()