Hi! My team is having trouble reproducing an injected .wav into a Programmer instrument. Here’s the code:
public static FMOD.Studio.EventInstance PlayCutsceneDialogue(string route, string key, Transform transform)
{
FMOD.Studio.EventInstance dialogueInstance = RuntimeManager.CreateInstance(route);
GCHandle stringHandle = GCHandle.Alloc(key, GCHandleType.Pinned);
dialogueInstance.setUserData(GCHandle.ToIntPtr(stringHandle));
dialogueInstance.set3DAttributes(RuntimeUtils.To3DAttributes(transform));
RuntimeManager.AttachInstanceToGameObject(dialogueInstance, transform, false);
return dialogueInstance;
}
No error on console. Working with 2.02.24. What they think it’s happening is that the path assigned to “key” is wrongly put. So I came here asking how is the path is written. And of course if you see any other problem, please do tell!
Hi,
Thanks for the info and code.
Can I confirm the issue is not hearing any audio from the programmer sound?
Would it be possible to apply the following settings:
And let me know if there are any additional logs in the console?
Could I grab an example of a key
you are passing in. When using in conjunction with an audio table, the keys can be found in studio:
We also have a scripting example here: Unity Integration | Scripting Examples - Programmer Instrument
Yes, the problem is that the audio is not being reproduced. We’re not using keys per se, but directly calling the wav itself in the folder (cause we’ll be using thousands of files so it’d impractical for them to have keys). Inside the audio table, it’s located on a folder that says “../Dialogue”. But we are not sure how to call each wav.
On log, this appears:
1 Like
Would it be possible to elaborate on this issue? FMOD generates the keys for you if that is the issue?
I have a example of playing a file using a programmer instrument here: General advice on user-friendly process for players to upload audio assets then pipe them through FMOD-powered Unity? - #2 by Connor_FMOD
Hope this helps!
What we think is the problem is that we are not setting the path correctly. So if I don’t assign a manual key, it’d be the path to where the file is, am I correct?
So, for a example, the path would be “ProjectName/Assets/Dialogue/NameFile”? Would there be anything we are missing?
Correct, you would just have to update the callback to correctly handle file paths:
[AOT.MonoPInvokeCallback(typeof(FMOD.Studio.EVENT_CALLBACK))]
static FMOD.RESULT YourCallBackFunction(FMOD.Studio.EVENT_CALLBACK_TYPE type, IntPtr instancePtr, IntPtr parameterPtr)
{
FMOD.Studio.EventInstance instance = new FMOD.Studio.EventInstance(instancePtr);
if (instance.isValid() == false)
{
UnityEngine.Debug.Log("Failed to create instance, instance invalid");
return FMOD.RESULT.ERR_EVENT_NOTFOUND;
}
//Retrive the user data
IntPtr stringPtr;
instance.getUserData(out stringPtr);
// Retrieving the path of the audio source from the user data
GCHandle stringHandle = GCHandle.FromIntPtr(stringPtr);
String location = stringHandle.Target as String;
switch (type)
{
case FMOD.Studio.EVENT_CALLBACK_TYPE.CREATE_PROGRAMMER_SOUND:
{
FMOD.MODE soundMode = FMOD.MODE.LOOP_NORMAL | FMOD.MODE.CREATECOMPRESSEDSAMPLE | FMOD.MODE.NONBLOCKING;
var parameter = (FMOD.Studio.PROGRAMMER_SOUND_PROPERTIES)Marshal.PtrToStructure(parameterPtr, typeof(FMOD.Studio.PROGRAMMER_SOUND_PROPERTIES));
FMOD.Sound audioSound;
FMOD.RESULT result;
// Creating the sound using the location of the audio source
result = FMODUnity.RuntimeManager.CoreSystem.createSound(location, soundMode, out audioSound);
if (result == FMOD.RESULT.OK)
{
parameter.sound = audioSound.handle;
parameter.subsoundIndex = -1;
Marshal.StructureToPtr(parameter, parameterPtr, false);
}
break;
}
case FMOD.Studio.EVENT_CALLBACK_TYPE.DESTROY_PROGRAMMER_SOUND:
{
var paramerter = (FMOD.Studio.PROGRAMMER_SOUND_PROPERTIES)Marshal.PtrToStructure(parameterPtr, typeof(FMOD.Studio.PROGRAMMER_SOUND_PROPERTIES));
var sound = new FMOD.Sound(paramerter.sound);
sound.release();
break;
}
case FMOD.Studio.EVENT_CALLBACK_TYPE.DESTROYED:
{
// Now the event has been destroyed, unpin the string memory so it can be garbaged collected
stringHandle.Free();
break;
}
}
return FMOD.RESULT.OK;
}