Load assets and soft references¶
Use a reflected property when a designer should pick an asset in Details. A hard reference gives your script the loaded object. A soft reference stores the asset’s path and lets you choose when to load it.
Let a designer choose a mesh¶
Add a mesh property to a Python actor, then place the actor in a level. Select it in the Outliner, open Assets → Mesh in Details, and pick a Static Mesh.
import ue
@ue.uclass
class MeshDisplay(ue.Actor):
display = ue.component(ue.StaticMeshComponent)
mesh: ue.StaticMesh | None = ue.uproperty(None, category="Assets")
def begin_play(self) -> None:
if self.mesh is not None:
self.display.set_static_mesh(self.mesh)
Resolve a soft reference¶
Python can read soft references from reflected Unreal properties or construct one from an asset path.
ref = ue.SoftObjectPtr("/Engine/BasicShapes/Cube.Cube")
mesh = ref.get()
if mesh is None:
mesh = ref.load()
get() returns the object if it is already loaded. load() loads it synchronously on the game thread and returns None if it is unavailable. Use ue.SoftClassPtr[T] for a reference to a class, such as a Blueprint actor class, when you want to load the class later.
For a designer-editable soft reference, declare it in Blueprint or C++ and read it from Python. A Python field can also hold a soft pointer as ordinary Python state.
Load by path¶
When you know the object path, ue.load_object() loads it directly. The path below refers to Unreal’s built-in Cube mesh.
mesh = ue.load_object("/Engine/BasicShapes/Cube.Cube")
For a project Blueprint with generated asset stubs, you can also import the class from ue.assets. Confirm that assets loaded by paths from Python are included in the cook, then test them in a Development package.