Hello everyone,
I have been building a UE plugin that can creating python editor tools for Unreal Engine, which makes creating menus, UE native Slate UI much easier and faster.
It’s FREE for use with community.
This is the website of the plugin
Feature
- Use UE4 native Python
- Create UE Slate UI dynamically, support 39+ Slate widgets.
- Configurable main menu/toolbar/Content Brower menu.
- Slate like syntax interface description file, real-time preview UI result, without any reload.
- Bind Python command to Slate UI widget, and change the UI content with python.
- No enging source code modified, compatible with lower versions of UE4(4.21, release later) and latest UE5
- 100+ Extra Editor Command for Python and Blutility. The full documentation is here which also can used in Blueprint.
Quick Start
The plug-in package contains several menu items and four demo tools by default.
The latest DefaultResources is here: DefaultResources@github
Menu Items
- Context Menu Items in Content Browser
- Context Menu Items for selected asset
- Menu Item in Main menu
- Menu icons on Mainbar
Blow tools all create with python and this plugin.
Sketch Tool for design/tweaking UI
The Sketch Tool is a special ui design tool. When <Your_UE_Projec>
\TA\TAPython\Python\ChameleonSketch\ChameleonSketch.json file is modified, the content of the ui will be updated immediately(see below gif). This can be very useful when writing tool interfaces, and will save a lot of time when tweaking the interface layout or parameters.
Tools 1 Shelf
Shelf is a Maya-like shortcut shelf tool, showing how to set visibility of widget and the usage of SDropTarget widget.
Users can drag and drop items to the shelf, and execute custom Python Code, launch Chameleon tool when clicking the item on the shelf.
(thisis a gif, click for play)
Tool 2 Object Detail Viewer
Object Detail Viewer is an inspector Tool for UE object. It shows all the functions and property in any UObject. Double click the property will query the child property. The image above shows the detail values of Floor_14(actor).static_mesh_component.static_mesh.static_materials[0].
In compare mode, the differences of two UObjects will be highlighted. It’s very useful for being familiar with all kinds of UObject.
(thisis a gif, click for play)
Tool 3 Chameleon Gallery
Chameleon Gallery shows the most common widgets, and how to describe them in a json file. All the supported widgets and API documents can be found here
(thisis a gif, click for play)
How to Install
1.Download from TAPython release repo @github and unzip the plugin to <Your_UE_Project>\Plugins
2.Laungch project, open Project settings - Plugin Python - additional path, add <Your_UE_Project>/TA/TAPython/Python to additional path. then restart the editor.
3.click the Gallery icon on main toolbar, you should see a green check box UI like below.
Green sign and text “Python Path Ready” will showing at the top of gallery.
Get start
This is a tool demonstrating the creation of a standard UE Slate UI with python and a json file. The Button calls Python code, then the python code sends the results(click count) back to the UI.
The tool includes a 30-lines Json file and a 15-lines Python file. In fact, it can be shorter.
I will call this kind of tool which creates Slate interfaces in this way “Chameleon Tools”
MinimalExample.json:
{
"TabLabel": "Example",
"InitTabSize": [200, 123],
"InitTabPosition": [680, 150],
"InitPyCmd": "import Example; chameleon_example = Example.MinimalExample.MinimalExample(%JsonPath)",
"Root":
{
"SVerticalBox":
{
"Slots": [
{
"SButton": {
"Text": "Click Me",
"HAlign": "Center",
"VAlign": "Center",
"OnClick": "chameleon_example.on_button_click()"
}
},
{
"SEditableTextBox":
{
"IsReadOnly": true,
"Aka": "InfoOutput",
"Text": ""
}
}
]
}
}
}
MinimalExample.py
# -*- coding: utf-8 -*-
import unreal
from Utilities.Utils import Singleton
class MinimalExample(metaclass=Singleton):
def __init__(self, jsonPath:str):
self.jsonPath = jsonPath
self.data = unreal.PythonBPLib.get_chameleon_data(self.jsonPath)
self.ui_output = "InfoOutput"
self.clickCount = 0
def on_button_click(self):
self.clickCount += 1
self.data.set_text(self.ui_output, "Clicked {} time(s)".format(self.clickCount))
I use MinimalExample for explaining how the Chamleon Tool works.
-
The content in MenuConfig.json defined the menu item for launching the MinimalExample tool. In this example, it’s “…/Python/Example/MinimalExample.json”
-
In MinimalExample.json, the content of “InitPyCmd” will be execute as python code, when the tool was launching. The “%JsonPath” will be replace by acture path automaticlly and passed to python tool class: “MinimalExample”. The variable: “chameleon_example” is in python global name space, using unique one in each Chameleon tool.
-
The base class of a Chameleon Tool is Singleton class in Utilities.Utils. The jsonPath been passed to the tool class in init function. In fact, the jsonPath is an id which is used to identify different chameleon tools. Also, the tool class will fetch the ChameleonData with it, and save it in local variable “self.data”. “self.data” is the key communication channel between UI widget and python code.
-
The content of “OnClick” in json, will be executed as python code, and call the function: “on_button_click” which defined in python chameleon tool.
-
“on_button_click” will record the click count, and send it back to the widget, though “self.data” which was mentioned in step 2
In above expample, we change the text through the the function “self.data.set_text”, and also can get/set other property of editor UI widges in similar ways.
Other APIs
More detail information and documents Welcome to UE Python Scripting Plugin: TAPython - TAColor
- Any suggestions and comments are welcome. Please don’t hesitate to leave your message. I need your feedback to make it better. Thanks