Announcement

Collapse
No announcement yet.

Capture all asset references

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

  • started a topic Capture all asset references

    Capture all asset references

    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()

  • replied
    I got tired of searching through the API, so i decided to make my own wrapper. Hopefully this will help someone.

    .cpp
    Code:
    //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
    Code:
    #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
    Code:
    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']
    Last edited by cgsquirrel2; 01-03-2019, 04:02 PM.

    Leave a comment:

Working...
X