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

Audio Does it use memory for same audio clip attached to many scripts

Discussion in 'Audio & Video' started by mikeohc, Aug 22, 2021.

  1. mikeohc

    mikeohc

    Joined:
    Jul 1, 2020
    Posts:
    215
    I have a script that picks a pool of sound effects to play randomly on an object. I have many of the same object with the script attached.

    Does audio reference take up memory per script reference or does it point to the asset?
    Screenshot (312).png


    I can understand audio manager for music and background audio, but for smaller things like sfx, referencing an audio manager for seems like a huge pain.
     
  2. JLF

    JLF

    Joined:
    Feb 25, 2013
    Posts:
    137
    My understanding of it is that multiple objects referencing the same audio clip doesn’t use more memory than one object i.e. they all reference the same clip in memory.

    if you want to double check though, the audio section in the profiler will show you how much memory is being taken up by audio.
     
    mikeohc likes this.
  3. mikeohc

    mikeohc

    Joined:
    Jul 1, 2020
    Posts:
    215
    Yes JLF is correct. All object reference the one audio clip.

    With that said, having an audio manager seems like a bad idea in this case.

    I've searched around and this article basically explains how preloading audio will cause the audio to load if any reference exist in scene, hence why audio manager in a persistent scene might be a bad idea especially if you use preload audio data.

    Without Preload Checked. Screenshot (313).png
    With Preload Checked.
    Screenshot (314).png