BasicMaterialInstanceSnapshot

View source

Value object that represents the serialized material reference of a BasicMaterialInstance. It carries material-instance persistence data across serialization and restoration; it is not an ECS component and does not hold a live material handle.

Examples

// `materialInstance` is a BasicMaterialInstance in `world`.
const serial = BasicMaterialInstanceSnapshot.serialize(
  BasicMaterialInstance.toSnapshot(materialInstance, world)
)
const restored = BasicMaterialInstance.fromSnapshot(
  BasicMaterialInstanceSnapshot.deserialize(serial), world, sceneAssetId
)

Constructor


constructor(handle: HandleSnapshot)

View source

Creates material-instance persistence data.

The supplied HandleSnapshot is stored as-is. This constructor does not clone the snapshot or resolve an asset.

Parameters

NameDescriptionDefault
handle

Snapshot of the material asset handle.

—

Properties


Methods


staticfromSnapshot(snapshot: BasicMaterialInstanceSnapshot, world: World, sceneAssetId?: AssetId): BasicMaterialInstance

View source

Restores a BasicMaterialInstance from this persistence data.

Path-backed snapshots are restored through the world’s AssetServer. Numeric snapshots require sceneAssetId and a matching scene asset mapping. If that mapping is unavailable, nested restoration returns undefined, and this method still constructs a component whose handle is undefined.

Parameters

NameDescriptionDefault
snapshot

Snapshot being restored.

—
world

World containing the AssetServer and, when needed, the scene asset mapping.

—
sceneAssetId?

Owning scene asset ID for a scene-local numeric handle snapshot.

—

Returns

Restored material component.

staticdeserialize(value: BasicMaterialInstanceSnapshotSerial, out?: BasicMaterialInstanceSnapshot): BasicMaterialInstanceSnapshot

View source

Rehydrates a snapshot from plain persistence data.

This does not restore a live handle. When out is supplied, this method updates and returns that same snapshot and passes its existing handle to nested deserialization, so the same nested handle object is reused; otherwise it creates and returns a new snapshot.

Parameters

NameDescriptionDefault
value

Serialized handle snapshot.

—
out?

Snapshot object to populate.

...

Returns

The populated snapshot.