> For the complete documentation index, see [llms.txt](https://bkortbus.gitbook.io/unreal-python-recipe-book/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://bkortbus.gitbook.io/unreal-python-recipe-book/actors/get-asset-from-actor/c++-get-asset-list-for-actor.md).

# \[c++] Get Asset List For Actor

Another option that might be worth pursuing is exposing C++ functionality to Python. Sometimes, if a Python option just isn't exposed or it's too inconvenient in Python, I'll try to find the C++ code for relevant actions in the Editor.

Unreal has a Right Click Menu option called <mark style="color:green;">Browse To Asset</mark> which will focus the Content Browser to the underlying asset of an Actor:

<figure><img src="/files/8H9vXyAkP2vxYFc4uiiC" alt=""><figcaption></figcaption></figure>

A lazy thing I'll do is find the relevant code in the C++ code and expose it to Python in a BP Function Library, here is an example c++ function we could add to gain access to this Menu's functionality:

The .h code:

```cpp
    /**  Get the Asset Data List for the provided Actor
     *  Sourced from UEditorEngine::GetAssetsToSyncToContentBrowser
     * @param  Actor the actor to query
     */
    UFUNCTION(BlueprintCallable, Category = "Python | Utils")
    static void GetAssetsForActor(TArray<FAssetData>& Assets, const AActor* Actor);
```

The .cpp code:

```cpp
void
UPythonUtilsLibrary::GetAssetsForActor(TArray<FAssetData>& Assets, const AActor* Actor)
{
    TArray<UObject*> Objects;
    Actor->GetReferencedContentObjects(Objects);
    for (UObject* Object : Objects)
    {
        Assets.Add(FAssetData(Object));
    }

    TArray<FSoftObjectPath> SoftObjects;
    Actor->GetSoftReferencedContentObjects(SoftObjects);

    if (SoftObjects.Num())
    {
        IAssetRegistry& AssetRegistry = IAssetRegistry::GetChecked();

        for (const FSoftObjectPath& SoftObject : SoftObjects)
        {
            FAssetData AssetData = AssetRegistry.GetAssetByObjectPath(SoftObject);

            if (AssetData.IsValid())
            {
                Assets.Add(AssetData);
            }
        }
    }
}
```

{% hint style="info" %} <mark style="color:yellow;">Note</mark>: This function has a different return than the Python example on the previous page
{% endhint %}

### Calling it in Python

With our c++ function compiled and the Plugin enabled, we can use the following logic to call it:

```python
unreal.PythonUtilsLibrary.get_assets_for_actor(actor)
```

And here is an example inspecting the current 3D Level selection:

```python
EditorActorSubsystem = unreal.get_editor_subsystem(unreal.EditorActorSubsystem)

actors = EditorActorSubsystem.get_selected_level_actors()

for actor in actors:
    asset_references = unreal.PythonUtilsLibrary.get_assets_for_actor(actor)
    if asset_references:
        print(
            f"Found {len(asset_references)} Content Browser Asset references"
            f" for Actor {actor.get_actor_label()}:"
        )
        for reference in asset_references:
            print(
                f"\t{reference.package_name} ({reference.asset_class_path.asset_name})"
            )
    else:
        print(f"No Content Browser Assets found for {actor.get_actor_label()}")
```

<figure><img src="/files/VoOde6n9oZMKt0InjyHG" alt=""><figcaption></figcaption></figure>
