20tab / UnrealEnginePython

Embed Python in Unreal Engine 4
MIT License
2.74k stars 743 forks source link

UEPY_THREADING Change causing Unreal 4.1.2 to close before the editor launches. #21

Closed crispy4004 closed 7 years ago

crispy4004 commented 8 years ago

The experimental UEPY_THREADING changes are causing Unreal 4.1.2 to not fully launch for me. Backing out of this commit resolves the problem. I'm not sure if this is also an issue with 4.1.3.

On the topic of threading, is it possible to run the "import_asset" and "asset_reimport" commands from a separate python thread? My guess would be it's not thread safe, but maybe there is way to have it execute on the main engine thread? Forgive my lack of knowledge on this, could see it being a complicated matter.

Asking because I'm currently launching an rpc-server on a separate python thread in the hopes of sending commands to the Editor from an outside python console. The server has a while loop to catch incoming connections and commands, which means I have to run it on a background thread in order to not pause the editor.

crispy4004 commented 8 years ago

Thinking about this more, it would probably require something like Houdini's executeInMainThreadWithResult() or Maya's evalDeffered(). Basically a way of deferring a function to run in the main thread when idle.

CreateAndDispatchWhenReady looks like the Unreal equivalent.

crispy4004 commented 8 years ago

It may also be possible to do it through PyQt's event handler like so. Have it working in a very limited test case. I'll know more tomorrow if it does what I need it to.

All that said, an engine level solution would still be ideal.

Amorano commented 8 years ago

I have done this cheating by simply launching a window (hidden) in the background during the ue_site.py intialization. You can then bury a any kind of messagebus/queue/etc... inside said window's loop to poll for events.

rdeioris commented 8 years ago

Hi, i have just added the create_and_dispatch_when_ready() method:

import unreal_engine as ue

def deferred_hello():
    ue.log_warning('I AM DEFERRED')

ue.create_and_dispatch_when_ready(deferred_hello)

currently it is pretty minimal, in the future we could extend it to support scoped events and other patterns

crispy4004 commented 8 years ago

Just a quick update, I haven't been able to use "create_and_dispatch_when_ready" due to the initial issue I posted in this thread that prevents the editor from launching, however the Qt workaround is working as intended. Successfully running remote calls on the main thread with the UnrealPythonEngine plug-in that is a few revisions behind.

crispy4004 commented 7 years ago

Just pulled the latest, the plug-in is loading successfully now in 4.12.