Python - Blender/Maya to UE4 using Remote Execution

Poking around the “” file I was able to create this rough test. The test basically returns an array of ue4 asset paths from ue4 back to the application running python.

To run the test you need to first, enable the python scripting plugin and turn on “Enable Remote Execution” under “Project settings” => Plugins => Python =>Python Remote Execution

Then in UE4, select a few assets in the asset browser and then run the below code in the python script editor in blender, maya, or whatever python terminal you got.

There are a lot of possibilities here!!

…Also I am looking forward to the release of “Blender - Send to UE4”

import sys
sys.path.append(r'C:\Program Files\Epic Games\UE_4.24\Engine\Plugins\Experimental\PythonScriptPlugin\Content\Python')
import remote_execution as remote

def executeCommand(command):
    remote_exec = remote.RemoteExecution()
    exec_mode = 'EvaluateStatement'
    rec = remote_exec.run_command(command, exec_mode=exec_mode)
    if rec'success'] == True:
        return rec'result']
    return None

#Based on the selected assets in the ue4 asset browser, return an array with asset paths
#'StaticMesh"/Game/art/Meshes/ST_gourd01.ST_gourd01"', 'StaticMesh"/Game/art/Meshes/ST_gourd02.ST_gourd02"']
def getSelectedAssetPaths():
    assetPaths = ]
    command = "str(unreal.GlobalEditorUtilityBase.get_default_object().get_selected_assets())"
    result = executeCommand(command)
    if result != None:
        string = result[2:-2]
        for e in string.split():
            path =  e.replace("\\'","").replace(",","")
    return assetPaths



Thank you for this example.
I integrated and modified your example to pass various commands to Unreal Editor from Maya. It worked very well for a while but now seems to be broken, and I’m getting the error:

RuntimeError: Remote party failed to attempt the command socket connection!

I double-checked and Enable Remote Execution is turned on in my project settings. I also checked that the socket id numbers were the same in the project settings as they are in the If you have any insights I’d be very grateful.

It’s been months since the last time I was testing this but I haven’t changed anything.

Very useful I’m using this remote_execution all the time now thank you !

I’ve been running into the same error. Did you ever find an answer?

Documentation on this is really bad but inside there’s a usage example at the end (if you run it as main).

The issue in above posted example is probably after remote_exec.start() you need to wait a bit to get the remote_nodes populated… adding time.sleep(2) after remote_exec.start() should do the trick…

Oh great! Thanks for the suggestion. Might be a couple things to tweak/try then.

I see in the _run_broadcast_listen_thread method there’s a _time.sleep(0.1) which might be a bit too short.

Using your suggestion, could query len(remote_nodes) for a period of time and break out the loop once remote_nodes has been populated. Otherwise timeout.
Cool, cool. Gives me a few things to playaround with. Cheers!

This might be part of the issue.
open_command_connection method expects a str, not a list.

If no remote nodes discovered, stop session and return False.
I’ve been logging out the command for debug purposes too.

With this change, so far things have been running smoother.
Hope this helps others that land here.

import logging

def executeCommand(command):
    remote_exec = remote.RemoteExecution()
    if remote_exec.remote_nodes:
        rec = remote_exec.run_command(command, exec_mode=remote.MODE_EXEC_STATEMENT)
        if rec['success'] == True:
            # Stop session 
            retrun True
    # Don't leaving session open if can't run
    return False
1 Like