Sequence events fire twice?

In working with the new level sequencer within release 4.12.5, I have discovered that the events on an event track fire twice? I’m not sure if this is the intended behavior but it certainly creates problems for blueprint scripts attached to the associated custom events that are only expecting it to fire once. There is already a bug(Level Sequence Event Duplicate Bug) that described this behavior but its resolution was lack of follow through. And that’s not adequate since there was really no answer if this is correct behavior or a bug. IMHO this should be a bug. Below is how I produce the issue in a brand new 4.12.5 project on Windows 10.

First create a simple scene with a sphere and add a level sequencer to the scene. Open the level sequencer editor and create a simple movement animation as seen in the image below. Next add an Event track and place a event at the 1.0 second mark(30 frames). Name the event using the properties by right clicking it.

Now open the level blueprint and duplicate the setup below. Be sure to name your custom event to the same name as was used in the sequencer event track. Mine was named Event1. I wired the P key to allow the sequence to be played again and again.

Now if you play this project and press the P key(or whatever key you wired up), you will see sphere move as expected but you will notice that the PrintString attached to the custom event(Event1) will actually print twice. Setting a breakpoint on the PrintString and pressing the P key again also confirms that it hits the PrintString node twice.

Note this is hard to work around because there is a timing element to it. You basically need to ignore the second event if it occurs within a certain delta time. Doing this really complicates the event handling is definitely not the preferred solution. I hope this issue can get some attention as we use this behavior extensively. Thanks.

Thanks for the detailed bug report.

This has been fixed and will be available in 4.13. The issue is that when the playback of the sequence is stopped, it returns the playback position to the start of the sequence and that caused all the events from the last playback position to the start of the sequence to be fired. Internally, we tracked this as bug UE-31494 and the changelist number that fixes this bug is 3019768.

Is there a way to get this fix prior to the 3.13 release so that I can include it into my local build? I don’t see a way to access the changelist(3019768) mentioned.

Please not that this bug occurs even when Stop has not been called. You can connect the sequencer player Play function directly to the Event BeginPlay and see this behavior. Note that it is important to have some kind of animation playing to see this behavior. With only an Event Track the problem is harder to reproduce.

I’ve debugged this issue a little bit and the problem seems to be in the following code

void UMovieSceneEventSection::TriggerEvents(TArray<UObject*> EventContextObjects, float Position, float LastPosition)
{
	const TArray<FNameCurveKey>& Keys = Events.GetKeys();

	if (Position >= LastPosition)
	{
		for (const auto& Key : Keys)
		{
			if ((Key.Time >= LastPosition) && (Key.Time <= Position))
			{
				TriggerEvent(Key.Value, EventContextObjects);
			}
		}
	}
	else
	{
		for (int32 KeyIndex = Keys.Num() - 1; KeyIndex >= 0; --KeyIndex)
		{
			const auto& Key = Keys[KeyIndex];

			if ((Key.Time >= Position) && (Key.Time <= LastPosition))
			{
				TriggerEvent(Key.Value, EventContextObjects);
			}		
		}
	}
}

The first if statement (Position >= LastPosition) is used for forward play and the else part of that if is for backwards play.
What I see happen in the debugger when playing in the forward direction, is that the if

((Key.Time >= LastPosition) && (Key.Time <= Position))

statement evaluates true for two different Position and LastPosition values. The Key.Time value is 1.0.

First it triggers at
Position=1.00000000, LastPosition=0.966666698

and then it trigger again at
Position=1.40000010, LastPosition=1.00000000

Seems to me with this logic there is always a possibility of the event firing twice.

If the previously mentioned bug doesn’t cover this use case, can we please create another bug to address this usage. Sometimes these issues are lumped in with a similar but different bugs and only part of the problem gets fixed. We would really like to see a fix for this make it into the 4.13 release. This is very important in allowing us to transition from matinee to sequences. Thanks again.

Can someone within Epic please see my response with my debug findings? I think this is a separate issue from the Stop scenario in bug UE-31494. Thanks.

Hi CodeTackler,

The change Max made to MovieSceneEventTrack.cpp was to add this from lines 47 to 54:

	// Don't allow events to fire when playback is in a stopped state. This can occur when stopping 
 	// playback and returning the current position to the start of playback. It's not desireable to have 
 	// all the events from the last playback position to the start of playback be fired.
 	if (Player.GetPlaybackStatus() == EMovieScenePlayerStatus::Stopped)
 	{
 		return;
 	}

if ((Key.Time >= LastPosition) && (Key.Time <= Position))
{
TriggerEvent(Key.Value, EventContextObjects);
}

current frame and next frame will trigger twice.
that is not a logic wrong?