QUESTION ll Randon Event everytime the scene load

Hi guys.

I want to make the gameplay music of my game more random, so every time the scene load, a different event with the music in it plays.
So far I being able to create some sort of script to create a list in which I can drag others gameObjects with the fmod emitter component inside and the music I choose.

this is the list in which i can drag the slaves gameObjects

So far the sound is working, every event is playing at the same time, my question is: is there a way to play on single event of this list every time the scene loads??

Hope you guys understand Im not a native english speaker.

this is the slaves which i can drag into the gameObject master which contains the script i created who create the list in it

this is my script so far, which let me see the list on the gameObject master



Thank you for the screenshots.

  1. The reason they are always triggering is that each event emitter has it’s Play Event Unity Integration | Game Components - Trigger Condition set to Object Start which will trigger the event when the object is created in the scene.
  • To stop this we will want to change the condition to None
  • Now, to start the random event we could use a random number to trigger a track from our list:
public List<FMODUnity.StudioEventEmitter> tracks = new List<FMODUnity.StudioEventEmitter>();
int trackToPlay = 0;
void Start()
	trackToPlay = Random.Range(0, tracks.Count);

private void OnDestroy()
  1. This method also removes the need for gameMusic as the event emitters contain their own event instances for us.
  2. This could also be done in FMOD Studio using parameters to control which audio track is played in an event, this would remove the need for any coding. An example can be found in the Example Project included in the FMOD Studio download: C:\Users\XXX\Documents\FMOD Studio\examples

Hope this helps!

1 Like

My brother it sure helps you save me!!!

just a couple of more question if I may:

how do I create probability for these list events???
is there a chance to add some type of function to stop playing the events already play until the list is complete??

thank you for your time replying this questions my good Connor I love you!!!

1 Like


No worries!

Could you elaborate on what you mean by this? If you a referring to the randomization then that comes from the Random.Range(0, tracks.Count) function which will return a number between 0 and the number of tracks in the list: Unity Docs | Random Range.

An option may be keeping track of the TrackToPlay numbers and if it is going to trigger the same number again you could just call Random.Range() again till you find a number that has not yet been used.

Hope this helps!

1 Like

hi thx for the reply!!!

let me elaborate further:

  1. saying probability i mean like every time the scene loads with the event list in it, this events inside could have some type of percentage (%) to be more probably to sound the event with 33% rather than one event who have only 2% from the 100% all the events share (i say this because i make some music event i would like to play only a very few times in the game, like an easter egg or something like that

  2. I would like to hear every event first rather than hear one event which already hear the last time scene load, don´t play an event which already play untill all other events in the list has been listened too…

i hope my grammar interfiere in the idea!!!

and one more question if i may:

in this script is there a way to create sometype of pause function on which the list pause the sounds when we call the pause method???

thx for you timeee

1 Like


So there might be an easier option in FMOD Studio for implementing this behavior rather than implementing it via code.

Using an FMOD Studio | Instrument Reference - Multi Instrument which allows you to create a list of single instruments to play with different percentages to play:
This will allow you to assign those easter egg files with lower percentage chance of playing.

Unfortunately, a multi-instrument won’t be able to remember which instruments it has already played from its list. However, with the code you could keep track of the trackToPlay value and make sure that it hasn’t already been called. I would suggest using a list that is saved during scene loading using DontDestroyOnLoad() (Unity Documentation - DontDestoryOnLoad()) then checking if the trackToPlay value is already in the list if it is then try find a new value. Else, the value is safe to play and can be used.

Hope this helps!