Multiple Programmer sounds in one event

For our project we need localization and we use programmer sounds for that. We also want to be able to play multiple programmer instruments in the same event. We tried to learn from the example in the API but we did not get the callback to work.
We use a class that inherits from the FMODAudioComponent. In that class we tried to set up a progammerSound callback.
In the .h file of that SoundComponent class we added following code.

// Programmer sound
struct ProgrammerSoundContext
{
	FMOD::System* coreSystem;
	FMOD::Studio::System* system;
	const char* dialogueString;
};
#define CHECK_RESULT(op) \
    { \
        FMOD_RESULT res = (op); \
        if (res != FMOD_OK) \
        { \
            return res; \
        } \
    }

FMOD_RESULT F_CALLBACK programmerSoundCallback(FMOD_STUDIO_EVENT_CALLBACK_TYPE type, FMOD_STUDIO_EVENTINSTANCE* event, void* parameters);
// Programmer sound end

In the cpp constuctor we added

FMOD::Studio::System* System = IFMODStudioModule::Get().GetStudioSystem(EFMODSystemContext::Max);
FMOD::Studio::EventDescription* eventDescription = NULL;
	System->getEvent("event:/Character/Dialogue", &eventDescription);
	FMOD::Studio::EventInstance* eventInstance = NULL;
	eventDescription->createInstance(&eventInstance);
	
	eventInstance->setUserData(&programmerSoundContext);
	eventInstance->setCallback(programmerSoundCallback, FMOD_STUDIO_EVENT_CALLBACK_CREATE_PROGRAMMER_SOUND | FMOD_STUDIO_EVENT_CALLBACK_DESTROY_PROGRAMMER_SOUND);
	
bAutoActivate = false;

In our dialogue class we have a play dialogue function which has this code in the end

Component->SetEvent(Event);
Component->SetProgrammerSoundName(Dialogue);

	FMOD_RESULT Result = Component->StudioInstance->setCallback(programmerSoundCallback);
	if (Result != FMOD_OK)
	{
		UE_LOG(LogTemp, Error, TEXT("Dialog::setcallback  failed"));
	}

	Component->Play();
	CanPlayQueuedDialogues = true;
	OnDialogueStart.Broadcast(Dialogue, Component);


We get error 30 “Invalid handle” for the setcallback function. Also studio instance seems to be Null. There is probably something fundamental we got wrong here.

If we can get the callback to work then we still haven’t found any information about how to play multiple programmer sounds in the same event. So some more information on that would also be nice.

We are using Unreal 5.1 github source code version with FMOD studio 2.0.2.06

Hi,

Apologies for the delayed response.

Could I get a screenshot of how you have the event set up in FMOD Studio?

Hello!

No worries, yes here is a screenshot of the event:

Thanks.

Hi,

Thanks for those.

Where does Event come from? I can’t see it being created using EventDescription->CreateInstance(&Component->StudioInstance).

Would it be possible to share the full code you are using? It can be uploaded to your profile or DM’ed to me.

Hi!

I think we use this BP function that we call in our dialogue class for creating the Event:

UFMODEvent* Event = UFMODBlueprintStatics::FindEventByName(path);

I’ve sent you a DM with the code.
Hopefully we can figure this out.

1 Like

The StudioInstance that you are accessing is part of FMODAudioComponent and is only being created when FMODAudioComponent::Play() is being called. Try adding this to the Dialogue Class

Creating the instance
Component->SetEvent(Event);
Component->SetProgrammerSoundName(Dialogue);
// Creating an Event description from the set event to use to create the instance
FMOD::Studio::EventDescription* dialogueDescription =  IFMODStudioModule::Get().GetEventDescription(Component->Event, EFMODSystemContext::Runtime);
dialogueDescription->createInstance(&Component->StudioInstance);

	FMOD_RESULT Result = Component->StudioInstance->setCallback(programmerSoundCallback);
	if (Result != FMOD_OK)
	{
		UE_LOG(LogTemp, Error, TEXT("Dialog::setcallback  failed"));
	}

	Component->Play();
	CanPlayQueuedDialogues = true;
	OnDialogueStart.Broadcast(Dialogue, Component); 

Give that ago