embedding unity player with pyqt5
Unsolved
Qt for Python
-
hi, am trying to embed unity player within my pyqt5 application.
the following code works good with displaying the content of the game, but the problem is I can't interact with the game at all.when I launch the game separately wherever I move the mouse I can change the camera view. but not any more with embedding it.
here is my current code:
import win32api import win32process from PyQt5.QtWidgets import QApplication, QWidget, QGridLayout, QLabel from PyQt5.QtCore import Qt, QProcess import sys import time import win32gui from PyQt5.QtGui import QWindow import ctypes if __name__ == '__main__': app = QApplication(sys.argv) main_window = QWidget() main_window.setMinimumSize(600, 600) container = QWidget() # Create layout grid_layout = QGridLayout(main_window) unity = QProcess() unity.setProgram("C:/Users/USER/My project (2)/win32/My project (2).exe") unity.start() unity.waitForStarted() time.sleep(15) # Get the window handle for the spawned Unity instance hwnd = win32gui.FindWindow(0, "My project (2)") UnitySceneWindow = QWindow.fromWinId(hwnd) unityWidget = QWidget.createWindowContainer(UnitySceneWindow, main_window, Qt.FramelessWindowHint) unityWidget.setFocusPolicy(Qt.TabFocus) # Get the thread IDs for the Qt and Unity windows qt_thread_id = win32api.GetCurrentThreadId() _, unity_thread_id = win32process.GetWindowThreadProcessId(hwnd) # Detach the Qt process input from the Unity process ctypes.windll.user32.AttachThreadInput(qt_thread_id, unity_thread_id, False) # Detach the Unity process input from the Qt process ctypes.windll.user32.AttachThreadInput(unity_thread_id, qt_thread_id, False) # Activate the Unity window ctypes.windll.user32.SendMessageA(hwnd, 6, 1, 0) main_window.show() app.exec_()
I read about the same problem with the following thread:
https://forum.unity.com/threads/unity-player-embedded-into-qt-application.537879/
but couldn't fix the problem
please help I was stuck with this problem 3days