Hi everyone,
I’m trying to create a small Python script for in Editor use, where I can send commands from a socket.io server to UE using Python.
It connects fine, Unreal is logging the messages, but because apparently socket.io is running on a different thread, I’m getting an error saying
LogUtils: Error: You are not on the main thread.
I remember that I had a similar issue in the past, with 3ds Max, and a developer from Autodesk created this example where he was using a mxthread module to force the code run on the main thread but I’m not sure how this can be used with Unreal.
This is the python code
import socketio
import unreal
# Create a Socket.IO client instance
sio = socketio.Client()
# Define event handlers
@sio.event
def connect():
print('Connected to server')
@sio.event
def disconnect():
print('Disconnected from server')
@sio.event
def message(data):
print('Received message:', data)
actors = unreal.EditorLevelLibrary.get_all_level_actors()
for actor in actors:
print(actor.get_actor_label())
# Connect to the server
sio.connect('http://localhost:3210')
and this is the Output log
LogPython: Connected to server
LogPython: Received message:
LogPython: Hi from the server
LogPython: Warning: W:/190205_Renderapp_RnD/build/CarConfigurator/Content/RenderappAssets/test.py:19: DeprecationWarning: EditorLevelLibrary: Function ‘get_all_level_actors’ on ‘EditorLevelLibrary’ is deprecated: The Editor Scripting Utilities Plugin is deprecated - Use the function in Editor Actor Utilities Subsystem
actors = unreal.EditorLevelLibrary.get_all_level_actors()
LogUtils: Error: You are not on the main thread.
Any help would be more than appreciated.
Nick