Im working on a project with fmod and unity and I was wondering if is possible to add some sort of randomness music events in one scene, let me explain further:
like Minecraft when you´re playing the game, songs trigger randomly in the back, i want to add some sort of thing in my scene which run the gameplay.
In FMOD I have my interactive music already set up, every track in a different event with some unique parameters to every event. My question: is there some sort of script to play a random event with all his parameters from a list you called???
i hope i explained well English is not my first language D:
Unfortunately there’s no existing script in the FMOD for Unity plugin that provides exactly what you need, but it’s entirely possible to create one yourself.
From your brief description, I would recommend the following:
Store a publicly exposed or serialized EventReference in your script that you can assign your events to via the Unity Inspector
When you need to play an event, randomly pick an event to play from your list of events, set parameters accordingly, and start the event with Studio.EventInstance.start()
If you want to start another event when the current one as finished, you can query the playback state of the current event with Studio.EventInstance.getPlaybackState()
This is a very general outline - if you can provide some more specific information on how your events are set up and the desired behavior, I may be able to provide more detailed guidance.
As I understand, you have several music events. Each of them is interactive. For example, event has parameters to change music from idle to fight or explore to suspence. You want to start one of events randomly and use these parameters to control music in game.
If I understand right. It’s good to have the same names of parameters you want to use in a game in each of those events. So, you can load different events but apply the same functions to change parameters.
yoursoundinstance.SetParameterByName(“Youparameter”, floatvalue)
Then you can use logic that Louis propose choosing random item from List
Simple one can looks like this. I didn’t check it may have some mistakes.
using FMODUnity;
public EventReference[] EventNames;
List<FMOD.Studio.EventInstance> soundInstances = new List<FMOD.Studio.EventInstance>();
int randomIndex = 0 ;
private void Start()
{
foreach (EventReference event in EventNames)
{
soundInstances.Add(RuntimeManager.CreateInstance(event));
}
}
public void StartRandomEvent()
{
randomIndex = random.Next(soundInstances.Count);
soundInstances[randomIndex].start();
}
public void ChangeParameter(float amount)
{
soundInstances[randomIndex].SetParameterByName("Parameter" , amount);
}
OnDestroy()
{
foreach (FMOD.Studio.EventInstance instance in soundinstances)
{
instance.release();
}
}
if something like this happens you need to check Microsoft docs and check what library specific command is using. In this case you need to add
“using System;”
Next thing, I’d recommend you to simplify system to one World to check if system works then add multiple arrays.
Sorry, it was my mistake. For now in the Start method foreach loop has no body and you need a variable name inside () different from your array name, lets call it worldEvent. You need also to add brackets { } and if you need to add events to soundinstances list. It should looks something like this