# Randomized Loops

**URL:** <https://forums.unrealengine.com/t/randomized-loops/628961>\
**Category:** Audio\
**Tags:** unreal-engine\
**Created:** [August 15, 2022, 5:26pm UTC](https://forums.unrealengine.com/t/randomized-loops/628961 "2022-08-15T17:26:53Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![DragonHeartSong](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DragonHeartSong](https://forums.unrealengine.com/u/DragonHeartSong)\
**Post date:** [August 15, 2022, 5:26pm UTC](https://forums.unrealengine.com/t/randomized-loops/628961/1 "2022-08-15T17:26:53Z")

</div>

UE4 … I had a clue how to do this and made a procedural music generator. I can make it work with sound cues.

With UE5 and metasounds, I am so lost and can’t even get the arrays to properly play.

I’ve followed a few tutorials, and those also aren’t providing results. So if you are able to help me trouble shoot, from scratch, it’d be appreciated.

My goal is to create a procedural music generator using different layers. Bass, Percussion, Chords - these are pre-recorded wavs, and edited to seamlessly layer with each other.

 ![BassPlayer](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/9/b/19b5342639ffc89716f0f615433d9c482a7722a7.jpeg)  
The bass plays and loops, yet there is no switching between the different loops. It picks one file and loops it.

 ![WavPlayerWithBass](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/c/8/8c8b7eba1421a49d0a3c6437bac6bd7ecc339a08.jpeg)  
This doesn’t even work, and as far as I can tell, it should.

It appears there are variables with delayed get for loop detection, and I can’t find an actual tutorial on how to make it happen. The blueprints I’ve seen are great, yet there are some steps in how to get from A to FINISH that I’m not understanding.

Is anyone willing to help me figure this out?

This is the documentation I followed : [How to Use MetaSound Presets | Tutorial](https://dev.epicgames.com/community/learning/tutorials/mXOv/unreal-engine-how-to-use-metasound-presets)

It turns out, in my blueprint that the ‘bass drum’ is the preset, and it isn’t playing. When I make it an array, it does play.

The first blueprint is the bass drum preset, and it plays, loops, but doesn’t randomize. I’d like to have it play a random number of times before switching.

---

<div class="post-metadata">

**Author:** ![ebuch](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ebuch/32/1071060_2.png) [@ebuch](https://forums.unrealengine.com/u/ebuch)\
**Post date:** [August 15, 2022, 8:09pm UTC](https://forums.unrealengine.com/t/randomized-loops/628961/2 "2022-08-15T20:09:15Z")

</div>

This post should help you:

> [@Setting Metasounds Variable](https://forums.unrealengine.com/t/setting-metasounds-variable/508262/19):
>
> Hey eagletree, Have you checked out using Variables with DelayedGet for dealing with loop detection? People using the end of a Wave Player to trigger another is a pretty common workflow, the syntax looks a bit like this: But, yes, PlayQuantized involves making a new MetaSound. It needs some time to queue the sound in advance in order to play sample-accurately, it’s a scheduler. (I think Max wrote a really detailed description of this somewhere, let me see if I can f…

You need to retrigger the random get by using a delayed get node like in the graph shared in the post I linked.

---

<div class="post-metadata">

**Author:** ![DragonHeartSong](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DragonHeartSong](https://forums.unrealengine.com/u/DragonHeartSong)\
**Post date:** [August 15, 2022, 8:19pm UTC](https://forums.unrealengine.com/t/randomized-loops/628961/3 "2022-08-15T20:19:16Z")

</div>

It’s a great blueprint and I’m sure if the details that are revealed in it were to be explained, I’d have my answer. However, the blueprint by itself doesn’t help b/c of the lack of details and how to get there. I do thank you for your effort though. 🙂

---

<div class="post-metadata">

**Author:** ![ebuch](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ebuch/32/1071060_2.png) [@ebuch](https://forums.unrealengine.com/u/ebuch)\
**Post date:** [August 15, 2022, 11:46pm UTC](https://forums.unrealengine.com/t/randomized-loops/628961/4 "2022-08-15T23:46:34Z")

</div>

Okay—the reason it is only looping one of your bass drum assets is because you are only triggering the Random Get once. The Random Get is picking a random bass drum and the Wave Player is looping that one asset.

Here is one way you could set this up.

 ![RandomRepeatRandomAsset](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/2/a/82a664b7044c51f67449215cbffa5c0e603eef0a.png)

You need to generate two random integers—one to use as a seed for selecting a random wave asset, and one to determine the number of times to play before switching.

On Play, you generate the random integers, select a wave asset, and play the wave asset. Then you count the number of times it has played. If the number of times it has played is less than the random number of times to play before switching, then loop the same wave asset again. If it is greater than or equal to the number of times to play before switching, then reroll the random integers and reset the Trigger Counter.

---

<div class="post-metadata">

**Author:** ![DragonHeartSong](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DragonHeartSong](https://forums.unrealengine.com/u/DragonHeartSong)\
**Post date:** [August 15, 2022, 11:47pm UTC](https://forums.unrealengine.com/t/randomized-loops/628961/5 "2022-08-15T23:47:28Z")

</div>

Most excellent, thank you so much! I’ll try this out.

---

<div class="post-metadata">

**Author:** ![ebuch](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ebuch/32/1071060_2.png) [@ebuch](https://forums.unrealengine.com/u/ebuch)\
**Post date:** [August 15, 2022, 11:50pm UTC](https://forums.unrealengine.com/t/randomized-loops/628961/6 "2022-08-15T23:50:52Z")

</div>

I’ve posted the graph as a snippet.

> **[Repeat a random asset a random number of times | Unreal engine Code Snippet](https://dev.epicgames.com/community/snippets/XKR/unreal-engine-repeat-a-random-asset-a-random-number-of-times)**
>
> Randomly selects a wave asset from an array and loops it a random number of times. Be sure to set the max values in hte Random (Int) nodes.

You’ll need to set up the variables but it should make it easier to copy/paste.

---

<div class="post-metadata">

**Author:** ![DragonHeartSong](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DragonHeartSong](https://forums.unrealengine.com/u/DragonHeartSong)\
**Post date:** [August 24, 2022, 4:23pm UTC](https://forums.unrealengine.com/t/randomized-loops/628961/7 "2022-08-24T16:23:04Z")

</div>

Ebuch, thank you! This worked! Your input is greatly appreciated!

---

<div class="post-metadata">

**Author:** ![ebuch](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ebuch/32/1071060_2.png) [@ebuch](https://forums.unrealengine.com/u/ebuch)\
**Post date:** [August 24, 2022, 9:33pm UTC](https://forums.unrealengine.com/t/randomized-loops/628961/8 "2022-08-24T21:33:57Z")

</div>

Very glad to hear that—best of luck with your project!

---

<div class="post-metadata">

**Author:** ![HYPAKILLA](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@HYPAKILLA](https://forums.unrealengine.com/u/HYPAKILLA)\
**Post date:** [May 23, 2025, 4:29am UTC](https://forums.unrealengine.com/t/randomized-loops/628961/9 "2025-05-23T04:29:42Z")

</div>

If anyone is wondering how to do what Eric suggested, “Loop” and “Randomize” are Trigger variables.

In order to get the variable with the clock icon next to it, you have to drag in the variable while holding the ALT key.
