Scripts are not changing parameter value

Hello There!
So I have an global parameter ‘AmbienceTime’ (local is working the same way as checked) that should send to FMOD event the hour of the day so the ambience would evolve around that, yet after few days of trying different approaches seen on forums, documentation, and after updating from 2.1.09 to 2.1.10, I have no idea why script that should update the value of that parameter is not making anything to it, anyone might have a clue what is missing here?

System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AmbienceControl : MonoBehaviour
{
[FMODUnity.EventRef]
public string AmbienceEvent = “event:/Ambience/General Day Ambience/Daytime System”;
FMOD.Studio.EventInstance AmbienceEv;

//AudioTime will be an updated outside variable showing an hour of day - float from 0 to 24
private float AudioTime = 8;

//works like a charm simply running an ambience event
private void Start()
{
    AmbienceEv = FMODUnity.RuntimeManager.CreateInstance(AmbienceEvent);
    AmbienceEv.start();
    
}

private void Update()
{
    var emitter = GetComponent<FMODUnity.StudioEventEmitter>();

    //this is a temporary solution to have Audiotime changed during play
    AudioTime = AudioTime + 0.01f;
    if (AudioTime > 24) { AudioTime = AudioTime - 24; }

    //a line that using different metodes (SetParameterByName, ...ByID) is not making any change to parameter 
    emitter.SetParameter("AmbienceTime", AudioTime);

    // shows that AudioTime works perfectly fine updating itself
    print(AudioTime);
}

}

well
after moving the script, in every way and going back to setParameterByName as it was in the very beginning somehow it managed finally to work :confused:

private void Update()
{
AmbienceEv.setParameterByName(“AmbienceTime”, AudioTime);
}

Glad you found a solution to this- It looks like the problem was due to calling SetParameter on the EventEmitter instead of the EventInstance. The EventEmitter version sets the initial value of the parameter whereas the EventInstance should be used for updating parameter values while it is playing.

1 Like

Hi, thanks for the tip, I guess I will make use of that in the future :+1:

Anyway, there is chance I was doing every approach that I found on the web back then bad, or it was some bug between FMOD and unity but after few days It was going fluently for me till the end of project :laughing: I wish there would be some clear description for that in some FMOD tutorials, as learning those stuff as I did was a massacre and I would say that I’m in comfort position of someone that quite understand coding (especially that most tutorials reflect scripting FMOD before 2.0 lol)

1 Like

I think the Karting Tutorial covers the basics of setting parameters and is a good one to check out if you haven’t already- though it sounds like you’ve gotten your head around it now. You are right though, we don’t have any youtube tutorials post version 1. I’ll see what’s going on there since we’ve dropped support for everything below 2.0

This is the exact method proposed in the documentation in the kart example (calling SetParamater on the emitter vs the Instance to provide continuous updates). This should be updated in the docs.

1 Like


In fact, the documentation explicitly says the exact opposite - that using the event is the correct way to handle updates.

1 Like

I had a very similar issue, which remains unresolved. Code in Unity is all passing to the functions and everything, but there’s some kind of disconnect between Unity and FMOD. setParameterByName is working on some scripts but not others in the same scene. Even in the same script, which changes a single parameter value twice, one of the changes is happening, and the other isn’t. Scratching my head over here. I’m using FMOD 2.02.05 and Unity 2021.3.2f1 (LTS).

I, too, am disappointed by the lack of updated information in the docs, and across the web. It seems like most help I can find is outdated.

I’ll post a forum question soon, but it was very simple. I had Global Parameters in FMOD, and I had to do something like:

void Awake()
{
FMODUnity.RuntimeManager.StudioSystem.setParameterByName(“EnterBossFight”, 1);
}

void Start
{
FMODUnity.RuntimeManager.StudioSystem.setParameterByName(“EnterBossFight”, 0);
}

I had tried every permutation of that possible, too much to type now. I also tried to do the same via SetParameter on an emitter, which works on another project I’m doing concurrently…

The only difference between my two projects right now is that one is using Unity 2021.3.2f1, and the other is using an older release. So, I’m guessing there’s a bug with FMOD/Unity right now?

Typing on my phone, so I may have small errors (autocorrects) in the code, but the point is, it’s not a difficult function. Just setting a value of 1, and then 0.

Apologies for the confusion- the problem appears to have been because you cannot set a global parameter using a Studio Event Emitter. I have passed a task onto the Dev team to address this issue.

The documented behaviour of calling SetParameter on an Event Emitter to change the parameter value of the Event Emitter’s event is correct.
@msyoung2012 Are you having any issues with setting parameter values that I can help you with?
@brownadm There could be a bug here which would be a separate issue. If you could please create a new forum post with your problem described in detail then we can help you figure out what might be going wrong.