Convert FFrameTime and FFrameNumber To Seconds

Converting FFrameTime and FFrameNumber to seconds while working with UE5 Sequencer API or other keyframe-based  systems in unreal engine.

This tutorial aims to be a soft landing for anyone needing to convert an FFrameTime to seconds while working with Sequencer API or otherwise. We also cover the reverse which is converting Seconds to FFrameTime.

Working With FFrameTime and Seconds

To convert seconds to FFrameTime or FFrameTime we will always need the framerate which is of class FFrameRate.

  1. How To Get FFrameRate In Unreal Engine

Both the UMovieScene and the UMovieScenePlayer are always aware of the FFrameRate of the Sequence. So depending on the class you currently have access to,  there should be a function to call to get the FFrameRate. For you movie scene it’s UMovieScene::GetTickResolution().
For other classes it maybe as simple as GetFrameRate(). Nonetheless there should be a function to get the FrameRate.

  1. How To Convert FFrameTime To Seconds

To convert FFrameTime to Seconds you need to divide it by the FFrameRate of the UMovieScene you’re currently working with. 

				
					double seconds=FFrameTime/FFrameRate;
				
			
  1. How To Convert Seconds To FFrameTime

To convert Seconds to FFrameTime you need to multiply it by the FFrameRate of the UMovieScene you’re currently working with. This is the opposite of the equation used to convert FFrameTime to Seconds.

				
					FFrameTime = Seconds*FFrameRate;
				
			

Working With FFrameNumber and Seconds 

You can work with FFrameNumber almost the same way as you with FFrameTime. FFrameTime seems to include subframes while FFrameNumber does not. Infact, the calculation to get the seconds is the same. 

  1. How To Convert FFrameNumber To Seconds in unreal engine

The calculations for FFrameNumber to seconds are the same with FFrameTime. You can just divide with the FFrameRate to get the seconds

				
					//Get FrameRate...

Seconds=FFrameNumber/FFrameRate;
				
			
  1. How To Convert FFrameNumber To FFrameTime in unreal engine

You can create an FFrameTime from FFrameNumber by using the FFrameTime constructor. FFrameTime has a constructor that takes in an FFrameNumber and from that you will get the FFrameTime.