import{_ as a,c as s,o as e,N as n}from"./chunks/framework.0799945b.js";const D=JSON.parse('{"title":"Dynamic Layers","description":"","frontmatter":{},"headers":[],"relativePath":"guide/advanced-concepts/dynamic-layers.md","lastUpdated":1681870292000}'),o={name:"guide/advanced-concepts/dynamic-layers.md"},l=n(`

Dynamic Layers

You can dynamically add and remove layers using the addLayer and removeLayer functions. It's important to note that removing a layer does not affect the player's save data. You can safely add and remove the same layer without losing any progress. For instances where the structure of a layer changes, such as when adding a new feature, use the reloadLayer function.

When procedurally generating layers with similar structures, consider using a utility function like the one below. This function allows you to access a correctly typed reference to a layer with a specified ID easily:

ts
function getDynLayer(id: string): DynamicLayer {
  const layer = layers[id];
  if (!layer) throw "Layer does not exist";
  return layer as DynamicLayer; // you might need an "as unknown" after layer
}

This utility function can streamline your code when dealing with multiple dynamic layers and ensure that you're working with the correct layer type.

When working with dynamic layers you'll need to ensure you can determine what layers should exist when loading a save file, by returning an accurate list from your project's getInitialLayers function.

`,6),t=[l];function r(p,c,y,i,d,u){return e(),s("div",null,t)}const h=a(o,[["render",r]]);export{D as __pageData,h as default};