Skip to content

Commit 0293449

Browse files
author
Roberto De Ioris
authored
Update README.md
1 parent 4207c05 commit 0293449

File tree

1 file changed

+62
-51
lines changed

1 file changed

+62
-51
lines changed

README.md

Lines changed: 62 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -780,55 +780,77 @@ It allows you to run, create, modify and delete scripts directly from the UE edi
780780

781781
The first pull request for the editor has been issued by https://github.com/sun5471 so many thanks to him ;)
782782

783-
Integration with PyQT
784-
---------------------
783+
Integration with Qt4/Qt5/PySide2
784+
--------------------------------
785785

786-
To correctly integrates PyQT with UnrealEngine the python plugin must correctly setup the GIL (and this is done) and exceptions must be managed ad-hoc (not doing it will result in a deadlock whenever a qt signal handler raises an exception)
786+
Thanks to solid GIL management, you can integrate Qt python apps in Unreal Engine 4.
787787

788-
This is an example of having a QT window along the editor to trigger asset reimporting (pay attention to the sys.excepthook usage):
788+
Pay attention to not call app.exec_() as it will result in Qt taking control of the UE loop. Instead use a ticker to integrate the Qt loop in the editor loop:
789789

790-
```py
791-
from PyQt5.QtWidgets import QApplication, QWidget, QListWidget
792-
import unreal_engine as ue
790+
```python
791+
792+
# save is as ueqt.py
793793
import sys
794-
import traceback
794+
import unreal_engine as ue
795+
import PySide2
796+
from PySide2 import QtWidgets
797+
798+
app = QtWidgets.QApplication(sys.argv)
795799

796-
def ue_exception(_type, value, back):
797-
ue.log_error(value)
798-
tb_lines = traceback.format_exception(_type, value, back)
799-
for line in tb_lines:
800-
ue.log_error(line)
800+
def ticker_loop(delta_time):
801+
app.processEvents()
802+
return True
801803

802-
sys.excepthook = ue_exception
804+
ticker = ue.add_ticker(ticker_loop)
805+
```
806+
now you can start writing your gui (this is a simple example loading asset thumbnail):
807+
808+
```python
809+
import ueqt
810+
from PySide2 import QtCore, QtWidgets, QtGui
811+
import unreal_engine as ue
803812

804-
skeletal_mappings = {}
813+
from unreal_engine import FARFilter
805814

806-
def selected_skeletal_mesh(item):
807-
uobject = skeletal_mappings[item.data()]
808-
ue.log('Ready to reimport: ' + uobject.get_name())
809-
uobject.asset_reimport()
815+
_filter = FARFilter()
816+
_filter.class_names = ['SkeletalMesh', 'Material']
810817

811-
#check if an instance of the application is already running
812-
app = QApplication.instance()
813-
if app is None:
814-
app = QApplication([])
815-
else:
816-
print("App already running.")
818+
class MyWidget(QtWidgets.QWidget):
819+
def __init__(self):
820+
super().__init__()
821+
self.vertical = QtWidgets.QVBoxLayout()
822+
self.scroll = QtWidgets.QScrollArea()
823+
self.content = QtWidgets.QWidget()
824+
self.scroll.setWidget(self.content)
825+
self.scroll.setWidgetResizable(True)
826+
self.layout = QtWidgets.QVBoxLayout()
827+
828+
for asset_data in ue.get_assets_by_filter(_filter, True):
829+
try:
830+
thumbnail = asset_data.get_thumbnail()
831+
except:
832+
continue
817833

818-
win = QWidget()
819-
win.setWindowTitle('Unreal Engine 4 skeletal meshes reimporter')
834+
label = QtWidgets.QLabel()
835+
data = thumbnail.get_uncompressed_image_data()
836+
image = QtGui.QImage(data, 256, 256, QtGui.QImage.Format_RGB32)
837+
label.setPixmap(QtGui.QPixmap.fromImage(image).scaled(256, 256))
838+
self.layout.addWidget(label)
820839

821-
wlist = QListWidget(win)
822-
for asset in ue.get_assets_by_class('SkeletalMesh'):
823-
wlist.addItem(asset.get_name())
824-
skeletal_mappings[asset.get_name()] = asset
825-
826-
wlist.clicked.connect(selected_skeletal_mesh)
827-
wlist.show()
840+
self.content.setLayout(self.layout)
841+
self.vertical.addWidget(self.scroll)
842+
self.setLayout(self.vertical)
843+
844+
845+
846+
widget = MyWidget()
847+
widget.resize(800, 600)
848+
widget.show()
828849

829-
win.show()
830850
```
831851

852+
(no need to allocate a new Qt app, or start it, as the UE4 Editor, thanks to to ueqt module is now the Qt app itself)
853+
832854
Memory management
833855
-----------------
834856

@@ -848,25 +870,14 @@ To run the unit tests (ensure to run them on an empty/useless project to avoid m
848870

849871
```python
850872
import unreal_engine as ue
851-
ue.sandbox_exec(ue.find_plugin('UnrealEnginePython').get_base_dir() + '/run_tests.py')
873+
ue.py_exec(ue.find_plugin('UnrealEnginePython').get_base_dir() + '/run_tests.py')
852874
```
853875
if you plan to add new features to the plugin, including a test suite in your pull request will be really appreciated ;)
854876

855-
Threading (Experimental)
877+
Threading
856878
------------------------
857879

858-
By default the plugin is compiled without effective python threads support. This is for 2 main reasons:
859-
860-
* we still do not have numbers about the performance impact of constantly acquiring and releasing the GIL
861-
* we need a better test suite
862-
863-
By the way, if you want to play with experimental threading support, just uncomment
864-
865-
```c
866-
//#define UEPY_THREADING 1
867-
```
868-
869-
on top of UnrealEnginePython.h and rebuild the plugin.
880+
Since release 20180624 threading is fully supported.
870881

871882
As with native threads, do not modify (included deletion) UObjects from non-main threads.
872883

@@ -908,12 +919,12 @@ What is going on here in `BadGuy` is that self.uobject is a reference to the PyA
908919
Status and Known issues
909920
-----------------------
910921

911-
The project could be considered in beta state.
912-
913922
Exposing the full ue4 api is a huge amount of work, feel free to make pull requests for your specific needs.
914923

915924
We still do not have a plugin icon ;)
916925

926+
We try to do our best to "protect" the user, but you can effectively crash UE from python as you are effectively calling the C/C++ api
927+
917928
Contacts and Commercial Support
918929
-------------------------------
919930

0 commit comments

Comments
 (0)