# FMOD - Unreal Callbacks in C++

**URL:** https://qa.fmod.com/t/fmod-unreal-callbacks-in-c/19261
**Category:** Unreal Engine
**Tags:** ue4, cpp, ue5
**Created:** [September 11, 2022, 11:44pm UTC](https://qa.fmod.com/t/fmod-unreal-callbacks-in-c/19261 "2022-09-11T23:44:22Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![horacv1](https://avatars.discourse-cdn.com/v4/letter/h/278dde/32.png) [@horacv1](https://qa.fmod.com/u/horacv1)
#### Post date: [September 11, 2022, 11:44pm UTC](https://qa.fmod.com/t/fmod-unreal-callbacks-in-c/19261/1 "2022-09-11T23:44:23Z")

</div>

Hello everyone.

I am trying to implement a simple callback in my C++ class. I already implemented the callback in Blueprints, but I want to translate the same system in CPP. I managed to load an FMOD Component and created and bound a delegate function too. The callback works, but it triggers the function on every beat.

How do I get a reference to the bar, beat, position, etc.? Getting these ints and floats is easy in Blueprints by calling the component event “On Timeline Beat”:

![BP_TImelineCallback](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/3/37bc85ba5c068499b7ed7da2ee5186858a841f1b.png)

The closest function I found in the UFMODAudioComponent::OnTimelineBeat class is .Broadcast(), but it asks for inputs instead of giving me references to these numbers.

This is how my constructor looks:

```auto
AMyCPPActorClass::AMyCPPActorClass()
{
 	
	PrimaryActorTick.bCanEverTick = true;

	StaticMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("StaticMesh"));
	
	FmodAudioComponent = CreateDefaultSubobject<UFMODAudioComponent>(TEXT("FMOD Audio Component"));
	FmodAudioComponent->SetEvent(myEvent);
	FmodAudioComponent->SetAutoActivate(false);
	FmodAudioComponent->OnTimelineBeat.Add(Callback);
	FmodAudioComponent->bEnableTimelineCallbacks = true;
	
	Callback.BindUFunction(this, TEXT("CppRotate"));
	
}

```

Maybe, I am implementing this system in the wrong way.  
Thank you for reading my thread and for any advice.  
Best!

---

<div class="post-metadata">

### Author: ![jeff\_fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/jeff_fmod/32/1766_2.png) [@jeff\_fmod](https://qa.fmod.com/u/jeff_fmod)
#### Post date: [September 15, 2022, 2:30am UTC](https://qa.fmod.com/t/fmod-unreal-callbacks-in-c/19261/2 "2022-09-15T02:30:26Z")

</div>

In your callback when the type is `FMOD_STUDIO_EVENT_CALLBACK_TIMELINE_BEAT`, `parameters` will be pointing to a [`FMOD_STUDIO_TIMELINE_BEAT_PROPERTIES`](https://fmod.com/docs/2.02/api/studio-api-eventinstance.html#fmod_studio_timeline_beat_properties) struct. To access the beat properties you just need to cast the `parameters` pointer, e.g

```cpp
FMOD_RESULT F_CALLBACK Callback(FMOD_STUDIO_EVENT_CALLBACK_TYPE type, FMOD_STUDIO_EVENTINSTANCE *event, void *parameters)
{
    switch(type)
    {
        case FMOD_STUDIO_EVENT_CALLBACK_TIMELINE_BEAT:
        {
            FMOD_STUDIO_TIMELINE_BEAT_PROPERTIES *beatProperties = (FMOD_STUDIO_TIMELINE_BEAT_PROPERTIES *)parameters;
            int beat = beatProperties->beat;
            int bar = beatProperties->bar;
            float tempo = beatProperties->tempo;
            break;
        }
    }
    return FMOD_OK;
}

```
