Announcement

Collapse
No announcement yet.

Python: wait for asset registry is loaded

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Python: wait for asset registry is loaded

    Hey there,

    I have the problem that my asset registry is not loading fast enough. I want to read all assets in a folder with a for loop and unreal.find_asset. The problem is, that I want to do this right after the start of unreal (the function is in a init_unreal.py). When starting Unreal, the assets can't be accessed and it prints the error: The AssetRegistry is currently loading.
    I tried several things to wait for the asset registry to be loaded, but Unreal freezes at this point (forever).
    That's one of my tries:
    Code:
    asset_registry = unreal.AssetRegistryHelpers.get_asset_registry()
    while True:
        is_loading = asset_registry.is_loading_assets()
        unreal.log_warning(is_loading)
        if is_loading == False:
            break
    is there a "unreal way" to wait for things to be loaded?

    Thanks in advance for your time and help.
    Last edited by Elias Kremer; 08-06-2018, 07:35 AM.

    #2
    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:

    Code:
    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.

    Comment


      #3
      Thank you again for your fast and great help!
      Good to know that the editor 'pauses' in the background.

      Comment

      Working...
      X