Skip to content

Prefabs

Swifter edited this page Feb 7, 2025 · 3 revisions

Prerequisites

Prefabs

You can access the prefabs from the bundle using the prefabs property. You might want to set that to a constant.

const prefabs = bundle.prefabs

The prefabs property will contain all the prefabs that are on your bundle.

img.png

On any given prefab, there are a few properties/functions

  • name - Simply the key of the prefab in the prefabs object
  • path - The path of the material in the asset bundle (e.g. assets/materials/myprefab.prefab)
  • instantiate - Allows you to create a prefab instance of this prefab.

(difficulty, beat = 0)

prefabs.myprefab.instantiate(map, 3)

You can also use an object {} to specify the id of the prefab instance and other properties.

prefabs.myprefab.instantiate(map, {
    beat: 0,
    id: 'myID'
})

Destroying Prefabs

You can use the destroyable objects system to more easily manage prefab instances.

const prefab = prefabs.myprefab.instantiate(map, 3)
prefab.destroyObject(6)

Assigning Objects With Prefabs

When using AssignObjectPrefab events, it is best to use the path property on prefabs you want to use instead of finding it manually.

rm.assignObjectPrefab(map, {
    colorNotes: {
        track: 'myColorNotes',
        asset: prefabs.mycolornote.path
    }
})

This will ensure if the path of the prefab changes, your script will automatically accommodate.

Clone this wiki locally