Search Unity

Unload referenced prefabs from memory

Discussion in 'Editor & General Support' started by KnightPista, Dec 6, 2016.

  1. KnightPista

    KnightPista

    Joined:
    May 18, 2015
    Posts:
    40
    Hi,

    When you reference a prefab, like in a public list of GameObjects or in Unity network manager list of spawnable prefabs, these prefabs are loaded into memory along with their textures, audios, meshes etc.

    The more prefabs are referenced - the more memory is used, which can cause problem on some memory-limited platforms.

    Is it somehow possible to Unload at least textures/materials/audios that the referenced prefab use?

    I know we can load prefabs using Resources.Load / Unload, but AFAIK all stuff from Resources folder is loaded on start automatically and having all prefabs in Resources folder is also not reccomended.

    Calling Resources.UnloadAsset(referencedPrefab); does not seem to work.

    Is it possible to have something like weak-reference to prefab, where textures/materials/audios/animations/meshes the prefab uses are loaded at the moment GameObject.Instantiate is called?

    Thanks for any help