Using a lambda to capture context in SubMix->AddEnvelopeFollowerDelegate in C++

I have a component that routes audio through various submixes and I’d like to monitor the signal of those submixes via the envelope follower provided on the submix. I’d like to encapsulate this logic in my C++ Actor component. However, the defined delegate seems to only be designed for BP which is quite limiting and in this case, prevents me from doing what I was hoping. I’d like to know if there is a way to know what submix’s envelope is getting updated on each callback (or ideally how to use a lambda as a delegate).


TArray<class USoundSubmix*> SubMixes;

I’d like to define a delegate for the envelope followers:

for (auto subMix : SubMixes)
  FOnSubmixEnvelopeBP delegate;
  // here I can only BindUFunction
  // so it looks like I need an OnEnvelopeFollowerNative like audioComponent->OnAudioFinishedNative
  subMix->AddEnvelopeFollowerDelegate(world, delegate);

Is there another way to get the delegate while capturing more context? I tried to find a way to dispatch a lambda but BindUFunction made me quite sad and I failed.


P.S: in case it would help others, until I find a better solution, I declared x function calls, where x is the number of submixes I have and then use them in my BindUFunction call. Super hacky but it works as a bandaid and probably better than forking UE.


		void OnSubmix4Envelope(const TArray<float>& Envelope) {
		OnSubmixGenericEnvelope(4, Envelope);
        auto world = GetWorld();
	for (auto i = 0; i < SubMixes.Num(); i++ )
		FOnSubmixEnvelopeBP delegate;
		// build a string using OnSubmix + i + Envelope
		FString name = "OnSubmix" + FString::FromInt(i) + "Envelope";
		delegate.BindUFunction(this, FName(name));
	    SubMixes[i]->AddEnvelopeFollowerDelegate(world, delegate);