releaseScene function Assets and loading

Future<bool> releaseScene(
  1. String sourcePath, {
  2. String? package,
  3. AssetBundle? bundle,
})

Releases one claim on the template loadScene built for sourcePath, dropping it from the shared cache when no claims remain.

Returns whether the template was dropped. A template holds the scene's realized geometry, materials, and textures, shared by every instance loaded from it, so this is the lever for unloading a level.

Dropping the template releases the engine's reference, not the memory. Nodes already realized from it keep their own references and stay resident until they are removed from the scene and collected. See Scene.memoryReport for what is actually resident.

Implementation

Future<bool> releaseScene(
  String sourcePath, {
  String? package,
  AssetBundle? bundle,
}) async {
  // Source-direct templates cache under their project-relative source key.
  final sourceKey = bundle == null
      ? activeSceneSourceLoader()?.resolveScene(sourcePath)
      : null;
  if (sourceKey != null) return _releaseSceneTemplateClaim(sourceKey);
  final registry = await SceneRegistry.load(bundle: bundle);
  final key = registry.resolveKey(sourcePath, package: package);
  return _releaseSceneTemplateClaim(key);
}