By default, a scene’s resources are loaded on-demand.
You can manually trigger the loading of all resources in a scene of for specific blocks by calling forceLoadResources
.
Any set of blocks can be passed as argument and whatever resources these blocks require will be loaded.
In this example, we will show you how to use the CreativeEditor SDK’s CreativeEngine to forcibly pre-load all resources contained in a scene.
public func forceLoadResources(_ ids: [DesignBlockID]) async throws
Begins loading the resources of the given blocks and their children. If the resource had been loaded earlier and resulted in an error, it will be reloaded. This function is useful for preloading resources before they are needed. Warning: For elements with a source set, all elements in the source set will be loaded.
ids:
: The blocks whose resources should be loaded. The given blocks don’t require to have resources and can have children blocks (e.g. a scene block or a page block).
Full Code
Here’s the full code:
let scene = try engine.scene.get()!
// Forcing all resources of all the blocks in a scene or the resources of graphic block to loadtry await engine.block.forceLoadResources([scene])
let graphics = try engine.block.find(byType: .graphic)try await engine.block.forceLoadResources(graphics)