Binding to MediaPlayer events in C++

How to get notified when MediaPlayer broadcasts an event?
To be specific I am trying to get notified about media that has been opened.
_
I found in UMediaPlayer code that I should bind my UFUNCTION to:

/** Multicast delegate that is invoked when a media player's media has been opened. */
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnMediaPlayerMediaOpened, FString, OpenedUrl);
FOnMediaPlayerMediaOpened OnMediaOpened;

_

but I can’t make my binding work:

// Header file
class MYAPI_API AMyActor : public AActor
{
	...
private:
	UMediaPlayer* MyMediaPlayer;
	UImgMediaSource* MySource;
	UMediaTexture* MyMediaTexture;

	UFUNCTION()
	void CatchMediaOpened(FString OpenedUrl);
	...
}

_

// CPP file
AMyActor::AMyActor()
{
	...
	MyMediaPlayer = NewObject<UMediaPlayer>(GetTransientPackage(), MakeUniqueObjectName(GetTransientPackage(), UMediaPlayer::StaticClass()));
	MyMediaPlayer->AddToRoot(); // Without this line adding delegate to Media Player event crashes the editor

	FScriptDelegate CatchMediaOpenedDelegate;
	CatchMediaOpenedDelegate.BindUFunction(this, FName(TEXT("CatchMediaOpened")));
	MyMediaPlayer->OnMediaOpened.AddUnique(CatchMediaOpenedDelegate);
	...
}

void AMyActor::LoadMediaSource()
{
	...
	MyMediaTexture->SetMediaPlayer(MyMediaPlayer);
	MyMediaPlayer->OpenSource(MySource);
	MyMediaPlayer->Play();
	...
}

void AMyActor::CatchMediaOpened(FString OpenedUrl)
{
	UE_LOG(LogTemp, Warning, TEXT("Debug: %s"), *OpenedUrl);
}

_
Could sbd point out what am I doing wrong? I tried to create MediaPlayer by my own inside editor too, but it also didn’t work. Binding dynamic multicast event in blueprint actor works correctly and I would like to do the same in code.

Hello! Can you replace this

CatchMediaOpenedDelegate.BindUFunction(this, FName(TEXT("CatchMediaOpened")));
 MyMediaPlayer->OnMediaOpened.AddUnique(CatchMediaOpenedDelegate);

with this

 MyMediaPlayer->OnMediaOpened.AddDynamic(this, &AMyActor::CatchMediaOpened);

And one more thing - declare you prop like this

UPROPERTY()
UMediaPlayer* MyMediaPlayer;

and you can remove adding to root logic.

There is no exposed AddDynamic function in MediaPlayer class… Or am I wrong?

@UPROPERTY() - Should I declare variables with this specifier if I want to create and manage objects only inside C++ and don’t expose it to blueprints?

AddDynamic is a MACRO and in fact it is in the list, but it is named there as __internal_AddDynamic. As for UPROPERTY - this macro guards you pointer from Garbage collection, also it is used to expose in Blueprints and at last is used in serialization and reflection.