Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Khena_B · Dec 18, 2016 at 11:30 AM · soundmemoryaudio sourceambient

Ambient audio

Hey,

I'm working on a 2D platformer and each rooms are new scenes, to prevent the ambient sounds from getting cut off during scene transitions i created a persistent level that is always active, and i've placed the ambient audio sources there, this way i'm able to hear a waterfall that is in another scene from a distance, for example.

My issue is that having the whole game's ambient sounds loaded in the memory sounds like a bad idea, and even if i only activated the audiosources when in range, the inactive audiosources would still have their audioclip loaded into the memory.

I'd like to know if it is possible to fill my whole gigantic persistent level with audio sources and not have them use any resources until the player is in hearing range, if not , do you guys have any suggestions?

Thanks

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by slavo · Dec 18, 2016 at 10:51 PM

You can set preloadAudioData in inspector of clip to false, and then just load and unload clips as you need them.

https://docs.unity3d.com/ScriptReference/AudioClip-preloadAudioData.html https://docs.unity3d.com/ScriptReference/AudioClip.LoadAudioData.html https://docs.unity3d.com/ScriptReference/AudioClip.UnloadAudioData.html

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Khena_B · Dec 19, 2016 at 12:24 AM 0
Share

I haven't heard of this before, most people have suggested that i use Resources.Load to load and unload clips from memory, when Preload Audio Data is set to false, an audio source won't have the audio clip taking memory at all until i call AudioClip.LoadAudioData? So loading it and unloading it should work with a trigger?

avatar image Khena_B · Dec 19, 2016 at 12:32 AM 0
Share

I've set Preload audio data to false and the audio clip still plays on awake.

avatar image Khena_B · Dec 19, 2016 at 01:10 AM 0
Share

It seems to work when i play, load and unload it manually, but when i call clip.UnloadAudioData(); I get a really long freeze, is it possible to unload the audio data without getting a big lag spike?

avatar image Khena_B · Dec 19, 2016 at 01:22 AM 1
Share

For some reason my OnTriggerEnter2D was being called repeatedly and loading the clip multiple times, once fixed and loaded once only, it can be unloaded without a hitch

I'll mark this as an answer, i'll have to run some tests but it seems to be the best solution so far, thanks for the help slavo.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Audio zones for ambient sounds 2 Answers

Unity 5 Audio Source volume falloff for mono sound without panning 0 Answers

Why does my audio stop working? 1 Answer

Change Audio source on collision 1 Answer

Clear microphone data 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges