Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 /
  • Help Room /
avatar image
0
Question by alexander_q · Jan 12, 2016 at 06:16 AM · uibuttonsoundaudio sourceaudio.playoneshot

PlayOneShot getting cut off

I have a button that opens an inventory screen. I want to play a sound when the inventory opens. In the inventory script I have:

     public AudioSource audio;
     public AudioClip trunkOpen;
 
     void OnEnable(){
         audio.PlayOneShot(trunkOpen,1.0f);
     }

Here is the clip I want to play:

alt text

Here is the audio source assigned to play it:

alt text

I've dragged the audio source, and the audio clip, to the inspector of the inventory script. The button enables the inventory screen. The sound is cutoff. I can't figure out why. There is no other sound playing.

Can you help?

n65kca5.png (23.3 kB)
mo844qj.png (27.1 kB)
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Diukrone · Jan 17, 2018 at 06:11 PM

Maybe a audioS.priority = Xf; could help you! Put 10f on priority to get highest priority on play. Try change áudio file by WAV files. Low priority sounds sometimes are virtualized on Unity. MP3 files have some bug behaviours on Unity, try use WAV.

You can try also changing the khz of the áudio files attached on a GameObject, like this example: GetComponent().Play (56), 128, 256, etc... So use it to Split the bits that it was recorded to gain some delay.

Comment
Add comment · 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
0

Answer by Atliinux · Feb 16, 2020 at 10:07 PM

I've encountered a similar problem where the start of any audio I play with PlayOneShot() would occasionally get cut off. This was solved by playing the clips through AudioSource.Play() instead.


From my testing, it seems like this problem is caused by lag, since AudioSource.PlayOneShot() would cut itself short at the start of the clip if I had to do any heavy loading operation (i.e. loading an inventory) on the same frame that I call PlayOneShot(). AudioSource.Play() fixes this problem because it seems to depend on the frame completing before playing, meaning it will not start playing the clip until any loading operations on that frame are completed.

Comment
Add comment · 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

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

48 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

C# On Click sound to play before loading scene 0 Answers

[Need help] How to higlight button color when passing the mouse after a click? 1 Answer

Playing a sound on all button presses? 1 Answer

How to add random number on a ui button?? 0 Answers

The count of buttons gives user 0 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