Has anyone had success on getting all the references of an asset? For example in the content browser a simple static mesh asset that has one material with one texture referenced? Maybe someone has a suggestion/ recommended reading?
I’ve tried the following and seem a bit confused as to how they work. I am not writing them correctly here, but wondering if i am heading in the right direction?
unreal.AssetTools.find_soft_references_to_object()
unreal.ShotgunEngine.get_referenced_assets()
I got tired of searching through the API, so i decided to make my own wrapper. Hopefully this will help someone.
.cpp
//removed other misc code, not sure if all the includes are here
#include "skpImportXml.h"
#include "ModuleManager.h"
#include "AssetRegistryModule.h"
TArray<FString> USkpLib::GetAssetDependencies(const FName& path)
{
FAssetRegistryModule& AssetRegistryModule = FModuleManager::GetModuleChecked<FAssetRegistryModule>("AssetRegistry");
TArray<FName> dependencies;
AssetRegistryModule.Get().GetDependencies(path, dependencies);
TArray<FString> dependencies_list;
for (FName& name : dependencies)
{
dependencies_list.Add(name.ToString());
UE_LOG(LogTemp, Warning, TEXT("Added deps: %s"), *name.ToString());
}
return dependencies_list;
}
.h
#pragma once
#include "Kismet/BlueprintFunctionLibrary.h"
#include "skpImportXml.generated.h"
UCLASS(Blueprintable)
class USkpLib : public UObject
{
GENERATED_BODY()
public:
UFUNCTION(BlueprintCallable, Category = Python)
static TArray<FString> GetAssetDependencies(const FName& path);
};
python
deps = ]
def getDep(assets):
for asset in assets:
array = unreal.SkpLib().get_asset_dependencies(asset)
if len(array) != 0:
deps.extend(array)
getDep(array)
getDep("/Game/StarterContent/Props/SM_Chair"])
print(deps)
#############################
LogPython: '/Game/StarterContent/Props/Materials/M_Chair', '/Game/StarterContent/Textures/T_Chair_M', '/Game/StarterContent/Textures/T_Chair_N']
2 Likes
You could try this, works for me.
unreal.AssetRegistryHelpers.get_asset_registry().get_dependencies('path/to/asset', unreal.AssetRegistryDependencyOptions())
Thanks for the reply, I managed to come across this a while ago, but didn’t get a chance to update this posting.
Having a way to handle all of this in the python api is much much easier to maintain. Cheers!
I moved some assets to another folder with unreal.EditorAssetLibrary.rename_asset, Is there a way with python API to reload all references or keep it while moving? Thanks
1 Like