+7 votes

How to loop an audio sample to play over and over again?

in Engine by (721 points)

1 Answer

+10 votes

First, when importing the sample, loop option has to be checked.
Then in SampleLibrary where the sound is imported, small pencil icon has to be clicked.

Now, the Inspector tab panel will show and let you set some of the properties of the imported sample.
Loop Format sets how to loop is going to be created:
None - no loop at all.
Forward - from start to the end and again from start to the end.
PingPong - from start to the end then reverse playing from end to the start.

Loop Begin indicates the start point of the loop.
Loop End, the point where loop will end.

After setting Loop Format for example to Forward, Loop Begin to 0 and Loop End to 1000000000, the sample will play from the very beginning to the very end, then when reaching the end will start to play again.

by (721 points)

Ok it's "decades" later now. But in case somebody stumbles upon this via google as I did, I want to mention something ;-):

In Godot 3.x you can set the Loop End to 0 if you want to let the sample loop from end to end (and don't know the exact length in bytes).

Setting to a very big value like mentioned above won't work anymore.

The way I'm making my music loop is to use finished() signal of the AudioStreamPlayer to play() the AudioStreamPlayer.

Good for music but won't be fast enough for samples. In 3.1 I now make sure that the samples "Loop" flag is set in the import settings. I also make sure that the loop start&end values are set on the wav file.

Also, don't forget to "reimport" the audio after you've ticked loop ;)
This got me for a while

It does still work, and is the only I got it to work for me.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.