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 Browse To Asset which will focus the Content Browser to the underlying asset of an Actor:
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:
/** 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);
And here is an example inspecting the current 3D Level selection:
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()}")