ShotgunEventDaemon and tk-unreal


When an artist hits Publish in Shotgun on an Asset mesh, we want it to automatically be imported into Unreal Engine 4, and submitted to the UE4 aware Source Control.


Convoluted. Suggestions welcome. Please see below.

I don’t \think\ the Shotgun Toolkit provides event driven support from Shotgun. Thankfully there’s the ShotgunEventDaemon.


Utilizing ShotgunEventDaemon we can make a plugin, modeled after or any other example, that attempts to communicate on a local port when an Asset Publish event happens with the asset id or another unique identifying piece of information.

I have to figure out from the myriad of Shotgun_PublishedFile_Change events, which I want to handle. I can probably handle ones with an attachment_id. I have to figure out from that information how to associate it with a specific Asset that I can import. That asset ID will be sent to a socket.

SG Toolkit Side:

Okay, on the SG toolkit side of things, I was thinking I need an app engine that can tap into tk-unreal to run an import.

If ShotgunEventDaemon service isn’t running, my plugin isn’t active on the port, I can have a thread/process spin it up from my tk app engine.

I can setup a thread to listen on the mentioned port, and when an asset comes in I can look up that asset to fetch it’s sg_publish_data.

After I get the asset data I need to figure out how to trigger an import. _import_to_content_browser in tk-unreal_actions is what’s called from execute_action. I need to figure out from a tk-unreal engine reference how to make that execute happen. I think I can access tk-unreal from another tk app using:


Or just:


From there I’m not sure how to get access to the

I don’t /think/ I can access tk-unreal unless Unreal is open, but wanted to be sure. When running Unreal’s Shotgun Python Console, tk-unreal is available from engine.tk_unreal; but if I’m running a toolkit app engine, I’m not sure if it would have access to the same information or not without doing a lookup mentioned above.


  • What’s the tk difference between Engine and other types, and and
    • I have to find and read through documentation, I’ll probably scratch this out and answer myself.
  • Is tk-unreal available before Unreal Engine itself is opened?
    • Can you trigger an import from the Shotgun App without needing Unreal open from the start?
  • If I have a tk app that depends on tk-unreal, how can I know when tk-unreal is started/shutdown and available for use?
  • Is there an easy way to trigger _import_to_content_browser from execute_action in tk-unreal_actions when you have access to the tk-unreal engine?
    • How do I get access to an Engine’s Hook Classes?


Has anyone done this before, and can you share details of what you went through?

Asked on UDN:

I setup a shotgunEventDaemon python plugin that acts as a client to connect to my python unreal plugin “server” on a certain port and send the event through the TCP socket.

I ended up using an Shotgun Toolkit Framework (instead of App or Engine) and making tk-unreal depend on it, so the framework would auto start and stop with tk-unreal. Within the framework I setup a thread to listen over a socket on the shared port, and this framework from the thread would trigger import events.

Having the listen thread in Unreal didn’t work. It seemed like Unreal didn’t keep python threads running. The Python threads only seemed to “pump” when I triggered user input and UE4 triggered some Python script. If I left UE4 in the background, no Python threads would run. Seeing as I’m trying to setup automated importing, this is a dead end without adding custom C++ calling code.

That opens up the question how to best pump a Python interpreter so it eventually yields for that frame; clearly UE4 doesn’t tick Python for threads, just they incidentally do that the few times it runs the interpreter.

Has anyone else here gotten UE4 python scripts to run as a daemon?

Oh right, and making sure the script runs on the game thread. I kept getting crashes on the rendering thread. Probably the wrong forum, but I figured I’d ask since this is “backed” by the Shotgun Toolkit and tk-unreal.