An asset or Unity object
have 3 ID as below
File GUID: a number to define location of the asset / unity object
Local ID: a number to distinguish between assets together
InstanceID = simpler format of 2 above ID generate by Unity.
Use large scene save more reload time than place asset or Unity object in Resource folder bc Asset in Resource folder when not use yet Unity still need serialize them to InstanceID.
Resources.UnloadUnusedAssets this only unload resource which there is no Mono reference to them.
- Resources.UnloadAsset API. The Instance ID for these Objects remains valid and will still contain a valid File GUID and LocalID entry. If any Mono variable or other Object holds a reference to an Object that is unloaded with Resources.UnloadAsset, then that Object will be reloaded as soon as any of the live references are dereferenced.
- Objects sourced from AssetBundles are automatically and immediately unloaded when invoking the AssetBundle.Unload(true) API. This invalidates the File GUID and Local ID of the Object's Instance ID, and any live references to the unloaded Objects will become "(Missing)" references. From C# scripts, attempting to access methods or properties on an unloaded object will produce a NullReferenceException.
When using AssetBundle should care about Dependency asset bundle and
If an application must use AssetBundle.Unload(false), then individual Objects can only be unloaded in two ways:
- Eliminate all references to an unwanted Object, both in the scene and in code. After this is done, call Resources.UnloadUnusedAssets.
- Load a scene non-additively. This will destroy all Objects in the current scene and invoke Resources.UnloadUnusedAssets automatically.