Load USD stage from Python

Hello,

I just begin to work with Unreal and try to evaluate the USD pipeline it provide. I would like to be able to load an USD stage from a python script on Startup.

I have try to use this code

import unreal 
from unreal import UsdStageImportFactory as usd_factory

factory = usd_factory()
task = unreal.AssetImportTask()
task.set_editor_property("filename", "C:\\Path\\To\\File.usd")
task.set_editor_property("destination_path", "Game/Content/")
factory.asset_import_task = task

unreal.AssetToolsHelpers.get_asset_tools().import_asset_tasks([task])

This code works for importing the USD in the project. What I want is just loading a usd file in the USD stage instead of importing in the project.

Is it currently possible through the Python API ? I only found USD importers related classes in the API documentation

Thanks for your help!

1 Like

I haven’t found the documentation of it, but by experimenting the found that creating UsdStageActor will make that stage available to Stage Window and modifying stage ‘root_layer’ property
will load that stage instead of importing and stage will also be available to edit

usd_stage_actor = unreal.EditorLevelLibrary.spawn_actor_from_class(unreal.UsdStageActor , unreal.Vector())
usd_stage_actor.set_editor_property("root_layer",unreal.FilePath( usd_file ))


"""
#To edit unreal stage 
from pxr import Ar, UsdUtils
stage_cache = UsdUtils.StageCache.Get()
stages = stage_cache.GetAllStages()
stage = stages[0]
"""

This code has been tested on 5.1

1 Like