When are resources outside the resource folder in memory?

I used Google Translator…Sorry :slight_smile:

I know that the resources in the resource folder are all up in memory when the client runs.

If so, are the resources outside the resource folder also packaged together in memory?

So its not really to do with when its ran, but rather when you build the project.

All files in resources will be loaded and used. Where as only the used files, gameobjects and prefabs in the assets folder will be loaded. If it is not used anywhere in your game it will not be loaded.

Assets have two main anchors which are responsible if an asset is actually included in a build and when it’s loaded. Those two anchors are:

  • The Resources folders (note you can have multiple folders. Any subfolder named Resources will also work)
  • The included scene files.

The Resources folder can be seen like static variables. Assets in those folders are always included in a build and always loaded at the game start.

Any other asset that is not in a resources folder will only be included if it belongs directly or indirectly to a scene that is included in the build settings. All the assets will essentially form a dependency chain and the top element is a scene. So for example a scene could contain a gameobject with a MeshFilter and a MeshRenderer component. The MeshFilter has a serialized reference to a Mesh asset. So that mesh will be loaded with the scene when the scene is loaded. Likewise the MeshRenderer will have a Material reference so that material will be loaded as well. The chain goes on. The Material asset will have a reference to a certain Shader asset and probably to one or multiple Texture2D assets. All those will be loaded with the scene.

There might be chains you haven’t considered yet. For example Prefab assets in the project might also have references to other assets. Another scenario:

The scene has a gameobject with a monobehaviour script. That script might have a public serialized field which references a prefab. That means the prefab is loaded with the scene. Keep in mind we talk about the prefab asset and not potential instances which might be inside the scene. The prefab can in turn have a different script attached which might reference other assets like a texture for example. All those assets need to be loaded since the script in the scene could use the prefab reference, access the script on the prefab and access the referenced texture.

If a certain asset is not directly or indirectly referenced by “scene 0” it will not be loaded when scene 0 is loaded. However such an asset might be used in “scene 3” and therefore has been included in the build but isn’t loaded in the beginning. Only when scene 3 is loaded everything referenced from scene 3 will be loaded.

All those “used” / referenced assets are usually packed with the scene that actually use those assets. To reduce the initial startup time you want to avoid unnecessary references to assets in the first scene. That’s why larger games often have an almost empty loading scene which might just show some initial information, a loading bar or a simple start menu.