finding objects\assets in CB

Hello! I’ve encountered several problems, and can’t find the solution. So if somebody knows how to do it, please share your knowledge :slight_smile:

  1. How can i load the object knowing its path?
    When using unreal.load_object(outer, name) - what does outer means (it returns an error if i’m trying to pass str path to the object in this arg)

  2. unreal.AssetRegistry.get_all_assets() - awaits for some arg and the docs doesn’t saying anything about it

  3. unreal.AssetRegistry.get_asset_by_object_path(object_path, include_only_on_disk_assets=False) - also returns an error if trying to pass str as object_path - TypeError: descriptor 'get_assets_by_object*_path’ requires a ‘AssetRegistry’ object but received a ‘str’*

so, outer is the class of the passing object, you can get in by using f.e.
from unreal import StaticMesh
unreal.load_object(StaticMesh.get_default_object(), loading_path)

Hey there,

As a newbie to coding for Unreal I’ve been struggling with some of this same stuff for the last few weeks. Hopefully I can save you some of the pain I went through :):

Try this instead:


unreal.load_asset(path_to_asset)
# Where *path_to_asset* would be something like:
path_to_asset = '/Game/SkeletalMeshes/Char1_Skeleton'

Instead of AssetRegistry, first use AssetRegistryHelpers to actually get the registry (I’m not sure I understand the logic but there you go):


asset_reg = unreal.AssetRegistryHelpers.get_asset_registry()
# Then you can "extract" the assets from the registry:
asset_reg.get_all_assets()

Similar to previous case:


asset_reg = unreal.AssetRegistryHelpers.get_asset_registry()
asset_reg.get_asset_by_object_path(path_to_asset)

Hope that helps.

2 Likes

Thanks, your suggestions were very helpful!

You are welcome. Glad that I was able to help.

Thank you!! Very useful overview.

You can also do

import unreal

editor_asset = unreal.EditorAssetLibrary()

# Search for an asset using a Path String such as
#  '/Game/ProjectName/Maps/Sandbox/Sandbox_P.umap'
# Game is the "Content" folder in Python
# This will return an AssetData class that contains a lot of usefull methods
# Check here: https://docs.unrealengine.com/4.26/en-US/PythonAPI/class/AssetData.html?highlight=assetdata#unreal.AssetData
search_for_asset = editor_asset.find_asset_data('pathstring')

# Now you can call the get_asset() method and receive the object that you can poss on to other functions
asset_get = search_for_asset.get_asset()

# You can for instance rename the file now
editor_util = unreal.EditorUtilityLibrary()
editor_util.rename_asset(asset_get, 'newnamegoeshere')