Variables in Metasounds

Hey, I’m new here. I’m sorry if I’m asking in the wrong place. I tried searching the forums, but couldn’t find an answer to my problem.

I have trouble understanding the variables in Metasounds. I wanted to make a patch that prints out the values in an array of type Bool for debugging, but I get the error “Connection causes loop”. The patch takes in the array and a trigger. I have a variable i to keep track of the index of the element to print. But when I want to increment i it won’t let me, saying the connection will cause a loop. I have a Value (Int32) node that I use to get the current value of i, I’ve connected the Output Value pin to a + node with a value of 1 and I’m trying to set the result to i to update its value. But it won’t let me connect the output from the Value node to the + node and set i node. I get the same error even if I use the delayed get of the variable.

Incrementing a variable to loop through an array is a very basic thing to do in programming, so I don’t understand why I can’t just do it. T_T

In a similar vein, why can you only set a variable once per Metasound graph? And why can there only be one output per graph? In programming you can set the value of a variable as much as you want and it doesn’t wear out. And you can litter your program with return statements if you so desire. Why do Metasounds have these limits?

Hey Cyber_punk, welcome to the forums!

Often the first mistake most people that are new to MetaSounds will make is assuming that MetaSound graphs will behave similarly to Blueprints or other visual scripting languages.

MetaSounds is a graph for processing buffers, (batches of audio samples that are sent to the audio renderer). Under the hood, this is done using a “directed acyclic graph” (DAG), which means the entire graph is evaluated simultaneously for each audio buffer. MetaSound graphs do not execute commands like Blueprints. (Triggers in MetaSounds are not the same as execution.) A good analogy here is the Material graph, which similarly does not have command execution—it’s a rendering graph. This means that variables like floats, ints, strings, and time are only updated once per buffer.

Why have these limits? Because the DAG enables sample-accurate precision for audio source generation and manipulation, arguably(?) the coolest aspect of MetaSounds.

I highly recommend you check out the video below by Epic’s Dan Reynolds—he dives deeper into the technical aspects of MetaSounds and covers much more than I can summarize in a forum post. Hopefully this gives you a bit more insight and points you in the right direction toward shifting your logic to “thinking in terms of buffers.”

Hey, thank you so much for your response and sorry I took so long to reply. When I asked for help I was already burned out trying to figure Metasounds out and so I needed a break from it. I’ll watch the video and hopefully it will make more sense then! :slight_smile:

1 Like