Answered
0
0

Hi,

I’m trying to learn how to add FMOD into games and how to code this so have got the Viking Village loaded up and am putting FMOD into this.

My current venture is to get an FMOD event to have its parameter changed without using the normal way of using triggers; I would like to change the parameter in code so it can react to the player pressing a button or waiting a certain amount of time. Right now I just want it to change to the player pressing a key on the keyboard.

I have a box with an event playing (using the event emitter) and have a script added to this object which is where I want to change the parameter. I’m very new to coding so only know how to make the code react to the player pressing a button, not having the code get the playing event and then change its parameter.

Any help would be appreciated.

Thank you for your time.

  • You must to post comments
Best Answer
0
0

[FMODUnity.EventRef]
public string NAME EVENT = “event:/EVENT”;
public FMOD.Studio.EventInstance AUDIO EVENT;
public FMOD.Studio.ParameterInstance PARAMETER EVENT;

void Start () {
AUDIO EVENT = FMODUnity.RuntimeManager.CreateInstance(NAME EVENT);
AUDIO EVENT.getParameter(“NAME PARAMETER FMOD”, out PARAMETER EVENT);
AUDIO EVENT.start();
}

void OnTriggerEnter(Collider other)
{
PARAMETER EVENT.setValue(VALUE IN FLOAT);
}

  • James

    Thank you for the answer!

    It all works (minus setting 3D attributes which is a separate issue) but it creates a new instance rather than changing one that’s already been made. Is there a way to do that or should I get rid of the event emitter and use this script only?

  • You must to post comments
0
0

Hey I would like to ask the same question

I have empty object on main scene with FmodStudio Emmiter attached. Music has two layers, volume of one of them is controlled by parameter.
Music begins with game start

I would like to set the parameter to 1 when fight beginsm and player stats are enabled.

Do I have to create an instance if its playing alredy?

  • James

    For setting a parameter straight away, FMOD’s event emitter has a little drop down called something like ‘Initial Parameters’. (Can’t remember off the top of my head).

    If you want to change a parameter during gameplay then you may want to get a new script that has a reference to the emitter. This new script should have whatever values you need, then on the emitter, call the method ‘SetParameter’. If that’s not the exact name, it will be something similar. This method lets you input the parameter name and the value you want to set.

    Hope this helps! Feel free to ask more questions (and I shouldn’t be on my phone then)

  • James

    For setting a parameter straight away, FMOD’s event emitter has a little drop down called something like ‘Initial Parameters’. (Can’t remember off the top of my head).

    If you want to change a parameter during gameplay then you may want to get a new script that has a reference to the emitter. This new script should have whatever values you need, then on the emitter, call the method ‘SetParameter’. If that’s not the exact name, it will be something similar. This method lets you input the parameter name and the value you want to set.

    Hope this helps! Feel free to ask more questions (and I shouldn’t be on my phone then)

  • You must to post comments
0
0

Hey,
Thanks a lot. I think i get the idea but all those variables, events, instances are very hard to understand for me

Could You tell me which scripts lines are responsible for makieng reference to event?

  • James

    Sure!

    So an FMOD event (the one you would use in FMOD Studio) is represented in code with a class called EventInstance which is in the FMOD.Studio namespace.

    Of course, having an EventInstance variable on a script and then doing things to it will result in a null reference error. This is where the event name comes in.

    Each FMOD event has a string and GUID ‘name’. You can right-click an event in FMOD and copy this ‘name’, or FMOD’s Unity integration has the ‘Event Browser’ under ‘FMOD’ in the toolbar, and have this stored in a string variable.

    The code will look a little like this:

    public string EVENT_PATH = “event:/Sfx/Gunshot/Shoot”;
    public EventInstance INSTANCE;

    To get INSTANCE to not be null (and reference an actual event) use RuntimeManager and call CreateInstance.

    This takes in a string or GUID. You would then input EVENT_PATH and the method will return an EventInstance. So the code would be something like:

    void Start ()
    {
    INSTANCE = RuntimeManager.CreateInstance (EVENT_PATH);
    }

    Now INSTANCE is not null and you can start and stop the event, set parameters and all the rest.

    Lastly, FMOD’s integration does come with a little more help.

    If you use the FMODUnity.EventRef attribute on EVENT_PATH then, while in the editor, you can get an event browser to come up in the inspector. This is the same thing as how FMOD’s StudioEventEmitter works and how you can select an event without copying the actual path.

    The code looks like:

    [FMODUnity.EventRef]
    public string EVENT_PATH = “”;

    Hope this helps! Feel free to ask more questions!

  • Maciej

    Thanks, I will try to do this. appreciate your help

  • You must to post comments
Showing 3 results
Your Answer

Please first to submit.