20tab / UnrealEnginePython

Embed Python in Unreal Engine 4
MIT License
2.77k stars 754 forks source link

Importing Assets From Complex Qt Dialog Crashes Editor. #441

Open c0ffymachyne opened 6 years ago

c0ffymachyne commented 6 years ago

Hi,

I ran into an issue Today where the same code is working when called from exemplary qt dialog but is causing Editor to crash during "save all" operation when called from more complex Qt UI. Not sure what may be causing it, debugger is pointing to Rendering component of the editor.

Literally UI like this with couple more buttons, QListWidget and QGridLayout added:

import sys
from PyQt4 import QtGui

class Example(QtGui.QWidget):

    def __init__(self):
        super(Example, self).__init__()

        self.initUI()

    def initUI(self):      

        self.btn = QtGui.QPushButton('Dialog', self)
        self.btn.move(20, 20)
        self.btn.clicked.connect(self.showDialog)

        self.le = QtGui.QLineEdit(self)
        self.le.move(130, 22)

        self.setGeometry(300, 300, 290, 150)
        self.setWindowTitle('Input dialog')
        self.show()

app = QtGui.QApplication(sys.argv)
ex = Example()
rdeioris commented 6 years ago

Hi, you should use the 'develop' branch for Qt integration as it has a stronger multithreading implementation (currently working on). In the next few days a new tutorial for Qt integration (PySide2) will be out. Btw if you use the develop branch you should have better threading support (heavily used by qt)

c0ffymachyne commented 6 years ago

Thank you @rdeioris . Will do.

rdeioris commented 6 years ago

Hi, this is what you can accomplish with 'develop' branch and commandlets:

import os.path
from unreal_engine.classes import PyFbxFactory
import unreal_engine as ue

import sys
from PyQt4 import QtGui

class Example(QtGui.QWidget):

    def __init__(self):
        super(Example, self).__init__()

        self.initUI()

    def initUI(self):

        self.btn = QtGui.QPushButton('Dialog', self)
        self.btn.move(20, 20)
        self.btn.clicked.connect(self.showDialog)

        self.le = QtGui.QLineEdit(self)
        self.le.move(130, 22)

        self.setGeometry(300, 300, 290, 150)
        self.setWindowTitle('Input dialog')
        self.show()

    def showDialog(self):
        # instantiate a new factory
        fbx_factory = PyFbxFactory()
        # build the path for the fbx file
        kaiju_assets_dir = os.path.join(os.path.expanduser('~/Desktop'), 'Kaiju_Assets/Slicer')
        slicer_fbx = os.path.join(kaiju_assets_dir, 'slicer.fbx')
        # configure the factory
        fbx_factory.ImportUI.bCreatePhysicsAsset = False
        fbx_factory.ImportUI.bImportMaterials = False
        fbx_factory.ImportUI.bImportTextures = False
        fbx_factory.ImportUI.bImportAnimations = False
        fbx_factory.ImportUI.bConvertScene = True
        # scale the mesh (the Kaiju is 30 meters high !)
        fbx_factory.ImportUI.SkeletalMeshImportData.ImportUniformScale = 0.1;
        # import the mesh
        slicer_mesh = fbx_factory.factory_import_object(slicer_fbx, '/Game/DumbKaiju/Slicer')
        slicer_mesh.save_package()
        slicer_mesh.Skeleton.save_package()

app = QtGui.QApplication(sys.argv)
ex = Example()

app.exec_()

you can run it with both UE4Editor.exe and UE4Editor-Cmd.exe

Basically you will end with a QT app running in UE4 environment, but without the editor gui