# Get Asset from Actor

A potentially desirable Actor interaction is getting its Content Browser Asset, the source asset of the actor currently in our scene.&#x20;

Frustratingly, I don't believe a magic bullet option is provided by the Unreal Python API directly that will work for any Actor type. We can still get the Content Browser Asset from just about any Actor, but we will need to make our own convenience function to achieve it.

***

## Getting The Asset By Actor Type

There are a number of different actor classes in Unreal, each with their own method of getting the underlying asset. Here is a collection of several such functions, depending on the actor type.

\
But first, here is a quick snippet to get the first selected actor in the viewport:

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

selection = EditorActorSubsystem.get_selected_level_actors()
actor = selection[0] if selection else None
```

With an actor reference, here are some of the more common code snippets to get their Content browser Asset:

### Blueprint Actor

```python
if isinstance(actor.get_class(), unreal.BlueprintGeneratedClass):
    asset_path = actor.get_class().get_outer().get_path_name()
    asset = unreal.load_asset(asset_path)
```

### Static Mesh Actor

```python
if isinstance(actor, unreal.StaticMeshActor):
    asset = actor.static_mesh_component.static_mesh
```

### Skeletal Mesh Actor

```python
if isinstance(actor, unreal.SkeletalMeshActor):
    asset = actor.skeletal_mesh_component.skeletal_mesh_asset
```

### Niagara Actor

```python
if isinstance(actor, unreal.NiagaraActor):
    asset = actor.niagara_component.get_asset()
```

### Level Instances Actor

```python
if isinstance(actor, unreal.LevelInstance):
    asset = actor.get_world_asset()
```

{% hint style="danger" %} <mark style="color:yellow;">Note</mark>: In earlier versions of UE5 it was unstable to hold onto unreal.World object references in Python, the full function demo will return this as a string path
{% endhint %}

***

## Full Function Example

```python
def get_asset_from_actor(actor):
    """
    Get the content browser asset path of the given actor,
    support must be added for each asset type

    parameters:
        actor: the actor to process

    returns:
        the actor's source asset (if supported & found)
    """
    asset = None

    # the source asset is usually stored on the root component
    # and is generally unique per component class type,
    # support will need to be added for each Actor class (joy)
    if isinstance(actor.get_class(), unreal.BlueprintGeneratedClass):
        asset_path = actor.get_class().get_outer().get_path_name()
        asset = unreal.load_asset(asset_path)
    elif isinstance(actor, unreal.StaticMeshActor):
        asset = actor.static_mesh_component.static_mesh
    elif isinstance(actor, unreal.SkeletalMeshActor):
        asset = actor.skeletal_mesh_component.skeletal_mesh_asset
    elif isinstance(actor, unreal.NiagaraActor):
        asset = actor.niagara_component.get_asset()
    elif isinstance(actor, unreal.LevelInstance):
        asset = actor.get_world_asset().get_outer().get_path_name()
    else:
        unreal.log_warning(
            f"\n\tActor {actor.get_actor_label()} has an unknown or unsupported source asset ({actor.get_class()})"
            "\n\t\tEither the actor does not have a source asset in the Content Browser"
            "\n\t\tor get_asset_from_actor() does not yet support its class type"
        )

    return asset
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://bkortbus.gitbook.io/unreal-python-recipe-book/actors/get-asset-from-actor.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
