rememberMaterial
Asynchronously loads a Filament Material and keeps it alive as long as the calling composable is in the composition. Returns null while loading and on failure — it never throws inside composition. Pass onError to react when load throws (missing file, network error).
Can be called either inside rememberFilamentScene { } (engine is picked up from LocalFilamentEngine) or outside it by hoisting the engine via rememberFilamentEngine:
// Inside rememberFilamentScene — engine implicit
rememberMaterial { Res.readBytes("…") }
// Outside a scene — engine hoisted, can be shared across scenes
val engine = rememberFilamentEngine()
val mat = rememberMaterial(engine) { Res.readBytes("…") }
val scene = rememberFilamentScene(engine = engine) { ... }Parameters
The Filament engine to allocate the material on. Defaults to the engine in the current composition scope, which only exists inside rememberFilamentScene { }.
Reloads the material when this value changes. Defaults to Unit for static assets.
Invoked once if load throws. The material stays null.
Suspend function that produces the raw .filamat bytes.