Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 1h2o1o377 · Apr 18, 2015 at 03:41 AM · audioaudiosourceaudioclip

AudioClip.Create() + PlayClipAtPoint() Not Working

Hi Unity friends,

I have a problem with loading and playing an audio file dynamically. I hope you can help! :-)

One. I have added an audio file called 01.wav to Resourses/SFX/ directory. The file is 44100HZ, stereo, 0:547 seconds long.

Two. The following MonoBehavior class works perfectly. I drag my audio asset on the "clip" field, then I call PlayAudioClip() and it plays it without a problem.

 public class SoundController : MonoBehaviour
 {
    public AudioClip clip;
 
     public void PlayAudioClip()
     {
         AudioSource.PlayClipAtPoint(clip, Camera.main.transform.position);
     }
 }

Three. But, when I try to dynamically create an AudioClip object from the file in a regular C# file (where there is opportunity to initialize an AudioClip with drag and drop), for some reason it doesn't play the sound for me. I can see the creation of "one shot audio" in the hierarchy, but no sound is played. Here is the code I'm trying:

 AudioClip clip = AudioClip.Create("SFX/01", (int)(0.547 * 44100), 2, 44100, false, false);
 AudioSource.PlayClipAtPoint(clip, Camera.main.transform.position);

I have tried various file formats and file settings, but they were not helpful. Also, I changed different address formats such as "Resources/SFX/01", "01" or "SFX/01.wav", but it didn't help either.

Thank you for your help! Cheers

Comment
Add comment · Show 3
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 jagels · Nov 25, 2015 at 09:21 AM 0
Share

Did you ever figure out any solution to this, @1h2o1o377? I'm currently having the same issue...

avatar image 1h2o1o377 · Nov 25, 2015 at 11:26 AM 1
Share

@jagels, I didn't find a way to solve the problem above, but I found another way to play clips: 1. Create a $$anonymous$$onoBehaviour class and attach its script to an object. 2. Add this public property to the class:

 public List<AudioClip> SfxClips = new List<AudioClip>();

  1. In the GUI drag and drop your audio files on top of the SfxClips list to populate it.

  2. Add this method to your class to play sfx clips:

    public void PlaySfxClip(int i) { AudioSource.PlayClipAtPoint(SfxClips[i], Camera.main.transform.position); }

Good luck! ;-) Cheers, Sia

avatar image 1h2o1o377 · Nov 25, 2015 at 11:29 AM 0
Share
 public void PlaySfxClip(int i)
 {
     AudioSource.PlayClipAtPoint(SfxClips[i], Camera.main.transform.position);
 }

0 Replies

· Add your reply
  • Sort: 

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

19 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

Related Questions

audio.clip.GetData() returns no data. 0 Answers

Unity 5 low audio volume 1 Answer

Stopping audio source without stopping oneshot clips 0 Answers

Unity Audio Output Data 0 Answers

How can I check the scene and play audio accordingly? 1 Answer


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