Trigger a Matinee from C++ code

Hello Everyone.
I would like to trigger a precise Matinee from a branch of an if statement inside my player class method. Is there a way to do it? if so can someone explain me how it works?
Thank you.

This is my method where I would trigger the Matinee:

void AFirstDemoCharacter::OnHit(AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)  
  {  
     if ((OtherActor != NULL) && (OtherActor != this) && (OtherComp != NULL))
    {
   	if (bActionPressed)
   	{
   		if (OtherActor->IsA(AButton::StaticClass())) 
   		{
   			if (!Cast<AButton>(OtherActor)->GetActive())
   			{
   				Cast<AButton>(OtherActor)->ToggleBActive();
   				// trigger Matinee here
   			}
   		}
   	}
    }
  }

There was already a post about this, I think it’s not exactly possible right now, but someone suggested a Work Around :

https://answers.unrealengine.com/questions/1921/request-playing-matinee-in-native-c.html

I have already seen that but what I am asking is if I can even trigger an event on the level blueprint at that part of my code so I can play the Matinee from there. Thank you for the answer anyway.

In that case, yes you can declare a delegate that will act as the desired event in your Blueprint that way :

DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FMyDelegate, float, aFloatVar);

UPROPERTY(BlueprintAssignable, Category = "Custom Matinee Event")
FMyDelegate OnReadyToDoMatinee;

Then, you can do this in your C++ code (where you put the “// trigger Matinee here” comment) to call it :

OnReadyToDoMatinee.Broadcast(0.0f);

Note that this is an example delegate for an event with 1 parameter (a float). There is macros in Unreal to do one without parameters, or multiple one. Search the code for DECLARE_DELEGATE for more info.

The next step is, in your Level Blueprint, have a reference to the object on which you did the previous code (in your case, AFirstDemoCharacter, so in your case I’m guessing

  1. Get Player Character
  2. Cast to AFirstDemoCharacter
  3. Assign OnReadyToDoMatinee

That last part is the important one, it will bind an event to OnReadyToDoMatinee delegate of your C++ class.

You should now have an event node (red) that will be called whenever you call “OnReadyToDoMatinee.Broadcast(0.0f);”

There, you can start your Matinee!

Thank you very much it worked perfectly, I’ve used the DECLARE_DYNAMIC_MULTICAST_DELEGATE and everything is fine.