Python: wait for asset registry is loaded

When the editor runs a Python script, it waits for that script to complete before doing anything else. So, when you do a while loop like that, your script blocks the editor from ever doing anything else. What you have to do is give control back to the editor so that it can continue initializing, but register your Python code to get run at a later time.

I was able to get this to work by registering a callback with the editor that gets invoked on every “tick” – that is, every time the editor UI is updated.

for example:


import unreal

tickhandle = None

def testRegistry(deltaTime):
    unreal.log_warning("ticking.")
    asset_registry = unreal.AssetRegistryHelpers.get_asset_registry()
    if asset_registry.is_loading_assets():
        unreal.log_warning("still loading...")
    else:
        unreal.log_warning("ready!")
        unreal.unregister_slate_pre_tick_callback(tickhandle)

tickhandle = unreal.register_slate_pre_tick_callback(testRegistry)


The “tick” only starts happening once everything is fully loaded, so in this case the “still loading” never happens. The first tick, the asset registry is ready. Then, I unregister the callback just to avoid having the code get triggered over and over again doing nothing.

2 Likes