Creating events in sequencer for 4.20

Hi there!

I’m trying to generate Movie Sequences from C++ from a dialog that I created as a custom asset. I want to call an event everytime a new Dialog Line is supposed to be displayed so I can print the adequate subtitle on screen at the right time.
So far I’ve managed to create sequences, event tracks and event keys from C++. My problem come when I want to send the right data to these event keys. From the editor, the keys only accept blueprint created struct, when I try to use mine, I can’t edit anything and the struct is not carried by the event.

Has someone ever done something like that and can help me :frowning: my last option if this does not work is to create my own event track but I’m not sure that it will be easy ^^’.

Here is the code I use :

// Adds an event track and section
	UMovieSceneEventTrack* EventTrack = CurrentSequence->MovieScene->AddMasterTrack<UMovieSceneEventTrack>();
	check(EventTrack);
	
	UMovieSceneSection* NewSection = NewObject<UMovieSceneSection>(EventTrack, UMovieSceneEventSection::StaticClass(), NAME_None, RF_Transactional);
	UMovieSceneEventSection* EventSection = Cast<UMovieSceneEventSection>(NewSection);
	check(EventSection);

	EventTrack->AddSection(*EventSection);
	EventTrack->SetDisplayName(LOCTEXT("TrackName", "Events"));

	// Get the event section's data to populate with keys
	FMovieSceneEventSectionData* EventChannel = EventSection->GetChannelProxy().GetChannel<FMovieSceneEventSectionData>(0);
	TMovieSceneChannelData<FEventPayload> EventData = EventChannel->GetData();

	for (int i = 0; i < DialogToGenerate->GetNumberOfLines(); ++i)
	{
		// create an event for this line, giving the speaker and text to the UI
		FEventPayload Payload;
		Payload.EventName = "SEQ_DisplayLine";
		//UDialogEventParams EventParams;
		PayloadProperty = NewObject<UDialogEventParams>(this, UDialogEventParams::StaticClass(), *FString("Sentence"), EObjectFlags::RF_Public);
		PayloadProperty->Parameters.DialogLine = FText::FromString("A line I want to display on screen!");
		PayloadProperty->PrepareCppStructOps();

		FMovieSceneEventParameters Params;
		Params.Reassign(PayloadProperty);

		Payload.Parameters = Params;
		//TODO : get the audio time to set the keyframe
		EventData.AddKey(i * 48000, Payload);
	}

Thanks in advance to anyone able to help here :slight_smile:

I did this in blueprints; the event cannot use the struct and each property of the struct must manually be added as an input to the event with the same name. To get around not being able to set the values of the struct, I created a property of an actor that I added to the sequencer and enabled Expose to Cinematics and then I was able to specify an actor if it was added to the level sequence. Also, I was not able to get events to fire when manually traversing the sequence.

1 Like

Thanks for the reply!
I thought about that but for my project it would be way better to do it in C++. And as I have a lot of data to go through, I need to be able to set the event’s parameters’ content in advance and cannot allow myself to create one Actor per event containing the data.
I also knew about the fact that you can’t send your structure directly as input and I created input pins for each field of my struct, but the event is only called when there is no input :frowning:

We found the solution. There was no need to create a custom UScriptStruct.

The way to do it was to populate the custom struct containing the parameters with the needed values. Then it is possible to get a UScriptStruct* from this struct by using the StaticStruct() method of the USTRUCT.
After that, one must use Reassign(TheCreatedUScriptStruct) on the FMovieSceneEventParameters. It will create a struct with default values, to get the values that we set before we must use OverWriteWith(TheFilledStruct), the parameter being the struct we populated earlier.

Here is an updated version of the code :

// Create the parameter struct and fill it
FEventPayload Payload;
Payload.EventName = "SEQ_DisplayLine";
FDialogEventParamsStruct ParamStruct;
ParamStruct.DialogLine = FText::FromString("A line I want to display on screen!");

// Get the UScriptStruct from the structure
UScriptStruct* PayloadProperty = ParamStruct.StaticStruct();

// Reassign and overwrite the parameter struct for the payload
FMovieSceneEventParameters Params;
Params.Reassign(PayloadProperty);
Params.OverwriteWith((uint8*)&ParamStruct);

// Create the event key
Payload.Parameters = Params;
//TODO : get the audio time to set the keyframe
EventData.AddKey(i * 48000, Payload);

I hope it can help somone with the same problem as it wasn’t easy to find =)

1 Like