Answered
0
0

Hi guys,

I am currently working on a porject with Unity and FMOD and so far everything works out fine. But now I have come to a problem: I want to play several events that are triggered at different points of a parameter from Unity. In FMOD i put the sounds on the parameter line to make sure they play on the exact points. In Unity I made a script for one shot events (with the help of your video tutorials, because I couldn’t find any manual on scripting with FMOD). I scripted, that an event only plays, when the play state isn’t playing already, because that way I wanted to make sure, that the sound doesn’t get played twice when the parameter stays on that value.

Then the problem was, that I had two sounds, that needed to be played close to each other (second one only one value further), so I created another event, to make sure, that if the first one is still playing, the other one can also be played and will not be left out, because there is still something playing.
I basically copied the script and only changed all of the names.

Now, if I start the project Unity will only play one of those two events and the other one gets ignored. If I deactivate the script of one, the other one is being played and vice versa. So on their own they are working fine, but being activated in parallel Unity will only play the first one.
And I thought that I had tried this out and that it was working fine (with both events playing parallel) but now not anymore. (even though I’m not sure if it really did do the job then or if I just didn’t recognize that it wasn’t…)

So I am wondering if you could help me out on that or have any suggestions on what the problem might be?
As i mentioned, I’m basically new to scripting and couldn’t find extensive tutorials/manuals.
Here’s the script:

[FMODUnity.EventRef]
public string sounds = “event:/Sounds/sound”;
FMOD.Studio.EventInstance soundEvS;
FMOD.Studio.ParameterInstance lineNo;

// Use this for initialization
void Start () {

    soundEvS = FMODUnity.RuntimeManager.CreateInstance (sounds);
    soundEvS.getParameter ("LineNo", out lineNo);

}

// Update is called once per frame
void Update () {

    if (realCounter != currentLine) {  //this is making sure, that the event doesn't get looped, when the value stayed on that position.
        FMOD.Studio.PLAYBACK_STATE play_state;
        soundEvS.getPlaybackState (out play_state);
        if (play_state != FMOD.Studio.PLAYBACK_STATE.PLAYING) {
            lineNo.setValue (realCounter);
            soundEvS.start ();

        }
        currentLine = realCounter;
    }
}
  • You must to post comments
Best Answer
1
0

Make sure you check out some of the examples in our documentation:
http://www.fmod.org/documentation/#content/generated/engine_new_unity/script_example_basic.html

From what I can see it looks fine, the only things that stand out are realCounter and currentLine, you haven’t included where they are being set. Double check they are being set correctly. Also if you are using a 3D sound without setting the attributes it may not behave the way you want it to.

You could possibly use the “FMOD Studio Event Emitter” script that comes with the integration, it also allows you to set the parameters initial values for each time it is triggered.
The “FMOD Studio Parameter Trigger” can then help adjust parameters after it has started.

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.