Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

AssetReference with AudioClips

Discussion in 'Addressables' started by Deleted User, Jul 13, 2018.

  1. Deleted User

    Deleted User

    Guest

    Hi there. I used AssetReference for loading AudioClip.
    Code (CSharp):
    1. _lobbyClipReference.LoadAsset<AudioClip>().Completed += (loaded) =>
    2.  {
    3.       _lobbyClip = loaded.Result;
    4.       PlayLobby();
    5.   };
    After scene changed, i trying release loaded asset and free memory.
    Code (CSharp):
    1. _lobbyClipReference.ReleaseAsset(_lobbyClip);
    But recieve a warning:
    ResourceManager.Release() - unable to find location info for asset MainTheme (UnityEngine.AudioClip).

    If i trying instantiate clip as game object, its works too, but also can't release:
    Code (CSharp):
    1. _lobbyClipReference.Instantiate<AudioClip>().Completed += (loaded) => { ...};
    2. ...
    3. _lobbyClipReference.ReleaseInstance(_lobbyClip);
    Recieve warning: ResourceManager.ReleaseInstance() - only GameObject types are supported

    What is the correct way to release AudioClips?
     
    Last edited by a moderator: Jul 15, 2018
  2. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,589
    Why do you instantiate an AudioClip asset?

    If you want to play an AudioClip, don't you have to assign it to an AudioSource instance and call play on the AudioSource instance or use AudioSource.PlayClipAtPoint instead?
     
  3. Deleted User

    Deleted User

    Guest

    Peter77, thanks for correction, i mean AssetReference.Instantiate and AssetReference.LoadAsset
    both allow you to get AudioClip. It works:
    Code (CSharp):
    1. _lobbyClipReference.Instantiate<AudioClip>().Completed += (loaded) => {
    2.      _lobbyClip = loaded.Result;
    3.       PlayLobby();
    4. };
    I have no problems with playing AudioClip, I want to find a way to release loaded AudioClips.