Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

I want to know how to unload ScriptableObject with plenty of data...

Discussion in 'Editor & General Support' started by erictang, Jul 8, 2014.

  1. erictang

    erictang

    Joined:
    Jul 28, 2012
    Posts:
    15
    I have a ScriptableObject asset ,contain thounds of float data,,,

    use Resources.Load to load this asset at runtime...

    but how to unload this ScriptableObject to release memory...when finishing calculation?


    I tried to use Destroy to unload the object ,but fail..

    eror occurs ...like this.

    Destroying assets is not permitted to avoid data loss. If you really want to remove an asset use DestroyImmediate (theObject, true);

    Code:

    void Start () {

    TestData td =Resources.Load("TestData")asTestData;
    Destroy(td);
    }
     
  2. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,276
  3. erictang

    erictang

    Joined:
    Jul 28, 2012
    Posts:
    15
  4. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,276
    What do you mean with " the sane" ?
    Do you get the "Destroying assets is not permitted to avoid data loss." error , or does it not work without a error?

    If its not throwing the error but not release the memory , the ScriptableObject is still referenced by some script , so it will be loaded again as soon as the referencing script needs it.
     
  5. erictang

    erictang

    Joined:
    Jul 28, 2012
    Posts:
    15
    I got an error...when I using Resources.unloadAsset to unload the scriptable object.

    UnloadAsset may only be used on individual assets and can not be used on GameObject's / Components or AssetBundles
    UnityEngine.Resources:UnloadAsset(Object)
     
  6. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,613
  7. erictang

    erictang

    Joined:
    Jul 28, 2012
    Posts:
    15
  8. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,613