Assets (Slot)

From Resonite Wiki
(Redirected from Assets Slot)
The Assets Slot on a mostly fresh world, as shown in the Scene Inspector.

The Assets Slot is a special Slot in every world's Root used to "store" assets outside the object themselves. This is necessary for otherwise-common papercuts when working with assets shared between objects.

Background: The Problem With Assets

Assets in a world always have to be represented by some form of Component. This implies that an asset is "part" of some object's slots, however assets are frequently shared between multiple different objects!

For example, if you import a new texture, a new object will be created with a StaticTexture2D component on it. If you then create a Material, it will create an different object with the appropriate material component on it. If you then put the texture into the material, the material will be storing a "reference" to the StaticTexture2D component.

This causes two pretty inconvenient problems:

  • If you destroy an object containing an asset (the texture in the example above, for instance), everything using that asset would break!
  • If you tried to save an object referencing an "external" asset, the asset itself would not be included!

Thankfully, neither scenario is something you have to frequently worry about thanks to the Assets Slot.

The Assets Slot

The Assets slot is a special slot at the Root of every world. Its job is to contain assets when they are not tied to any one object in specific. It contains many child slots of the form "X - Assets", each having different asset components. There are two ways assets end up in the assets slot: deletion, and spawning.

Deletion

If you look at the Scene Inspector, there are two buttons to destroy slots: "Destroy", and "Destroy Preserving Assets". If you press the regular "Destroy" button, the slot will be destroyed, and any asset components underneath it will also be destroyed. However, the "Destroy Preserving Assets" button does something different: it moves assets into the Assets Slot prior to deletion. This means they will not be destroyed along with their slots, and references to them keep working.

"Destroy Preserving Assets" is used by most "destroy" buttons outside the Scene Inspector automatically. For example, grabbing an object and destroying it with the Context Menu does a "Destroy Preserving Assets" automatically.

Saving and Spawning

If you save an object which references assets outside itself, those assets do get saved in practice! When the object is spawned in again, the components instead get spawned in underneath the Assets Slot. This means no new slot has to be made on the object itself, and it behaves consistently (i.e. hard destruction would not destroy the asset components themselves).

Automated Cleanup

As shown above, there are multiple ways for things to get into the Assets Slot, usually implicitly without people directly being aware. However this poses somewhat of a problem: it is very easy for stuff to pile up there. If you spawn in a bunch of objects that use external assets, deleting the objects will not destroy the assets in the assets slot, even though they may very well be completely unused. Furthermore, it is automatically dangerous to manually destroy anything in the Assets Slot, as it's impossible to know what uses it before pressing the destroy button.

Luckily, Resonite will automatically clean up the Assets Slot, removing all assets that are unused by the rest of the world. It does this at two points:

  • On a configurable interval, if "Cleanup Unused Assets" is enabled in the Session settings.
  • When the world is saved.

As such, you generally do not need to worry about the Assets Slot filling up with garbage.