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 hyliandanny · Mar 21, 2012 at 08:19 AM · audiosoundloopmusic

Why Doesn't My Music Loop?

I have an audio clip that plays when my game starts up, but it doesn't loop. I'm not sure why it doesn't loop.

Here's the code exactly as it stands, it's not too complicated.

 #pragma strict
 
 function Start () {
     AudioSource.PlayClipAtPoint(audio.clip, Camera.main.transform.position);
 }
 
 function Update () {
     
     // Play the audio for this image
     if (audio.isPlaying != true)
         AudioSource.PlayClipAtPoint(audio.clip, Camera.main.transform.position);
         
     Debug.Log(audio.loop);
 }


The Debug.Log line is reporting true. My music ends, and the sound does not get played again. How do I get my sound to loop?

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

5 Replies

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

Answer by hijinxbassist · Mar 21, 2012 at 09:02 AM

Have you actually physically checked that the audio sources loop is set to true(box with check mark). If not, un click "Maximize On Play" and look at the offending audio source while the game is playing.

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 hijinxbassist · Mar 21, 2012 at 09:07 AM 0
Share

Also, keep looking at the audio source after the sound has finished. This will help deter$$anonymous$$e what is wrong. Just for testing, add this new line to your script....

 function Start () 
 {
     AudioSource.PlayClipAtPoint(audio.clip, Camera.main.transform.position);
     transform.GetComponent(AudioSource).audio.loop=true;
 }
avatar image hijinxbassist · Mar 21, 2012 at 09:13 AM 0
Share

Is the source parented to your camera, if not...then this is the problem. There needs to be an AudioListener in range of the AudioSource. If this is its own GameObject, parent it to the camera. Simple as that, the more i think about it, the more i think this is the issue. You have it play at the cameras position, but then you move and no longer hear it(i cant say for sure without seeing actual game play).

avatar image hyliandanny · Mar 21, 2012 at 05:29 PM 0
Share

Thanks, attaching the audio source and script to my camera -- ins$$anonymous$$d of my background game object -- made it actually loop after the sound finished playing.

I'm also really happy that this led to me being able to use "audio.Play()" as advertised. It wouldn't work, before, likely because of some camera hijinx that I don't know about.

avatar image static_cast · Nov 29, 2014 at 02:11 AM 0
Share

Please don't reply to a 2 year old thread. Ins$$anonymous$$d, make your own. :)

Don't use Debug.Log() for this because it will keep echoing over-and-over and dropping the framerate.

avatar image
0

Answer by Kryptos · Mar 21, 2012 at 04:36 PM

You can't loop sounds started with AudioSource.PlayClipAtPoint. This method doesn't use the AudioSource component of your object but instead creates a temporary (and hidden) object. This is the intended behaviour.

As mentioned in documentation, you can use an alternative method. See http://unity3d.com/support/documentation/ScriptReference/AudioSource.PlayClipAtPoint.html for more details.

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 theropodx · Jun 29, 2012 at 02:12 AM

Strange, the "alternative method" from that link has disappeared. Maybe Unity removed that function in the latest build? Anyway, it's missing from the doc link above now.

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 Vetpetmon · Nov 29, 2014 at 02:09 AM

When I used the code it would also try to crash my computer with it spamming 379 messages saying "True" per 30 seconds, any fixes? It lagged so badly it dropped me down to 0 Frames Per Second, I spent 10 minuets to restore my computer's memory usage to normal. EDIT: Now it's spamming the music! EDIT:IT WORKS!!!:

  #pragma strict
  
  function Start () {
      AudioSource.PlayClipAtPoint(audio.clip, Camera.main.transform.position);
      transform.GetComponent(AudioSource).audio.loop=true;
  }
  
  function Update () {
      
      // Play the audio for this image
      if (audio.isPlaying != true)
          AudioSource.PlayClipAtPoint(audio.clip, Camera.main.transform.position);
          
  }
 


Thanks, that helped a lot.

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 kfirmon · Oct 03, 2015 at 02:38 PM

The problem might be a result of using "Play on awake". I attached a script to the Audio Source instead and it solved the problem.

 using UnityEngine;
 using System.Collections;
 
 public class MusicPlayer : MonoBehaviour 
 {
     public AudioClip clip;  // Drag the clip here on the editor
     private AudioSource au;
 
     void Start() 
     {
         au = GetComponent<AudioSource>();
         au.loop = true;
         au.Play();
     }
 }
 
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

7 People are following this question.

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

Related Questions

Trigger audio loop on beat with PlayScheduled 1 Answer

Background music 0 Answers

How do i add/import sound effects and/or music into my game? 5 Answers

Can't get a sound to loop 2 Answers

Theme music for approach to object question 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