Is it possible to import focal length animation onto a camera in Sequencer?

Does anyone know if it’s possible to get the focal length to import from an fbx onto a camera that exists(as a spawnable) in sequencer?

I’ve never written python code before but I’m attempting to make a UI for importing animation, and building sequences. I’ve got pretty much everything working, except I can’t get focal length animation to import onto a camera in sequencer. I can get translation animation to import, but not focal length. I’m guessing it has something to do with the fact that the focal length attribute is on the CameraComponent, or maybe unreal.SequencerTools.import_fbx() doesn’t read focal length from the fbx? I dunno…

Another weird thing is that the ‘reduce_keys’ property of unreal.MovieSceneUserImportFBXSettings() just gets ignored, whether True or False. All the other properties work, but that one doesn’t. If I manually import a camera before running my script, my script will use whatever the property was set at during the manual import. I guess I can live with this, but it’s a bit weird.

Here is the code I am using to import camera animation. Am I doing something incorrectly?:


import unreal

world = unreal.EditorLevelLibrary.get_editor_world()
sequencer_asset_path = '/Game/Sequences/CameraTest_seq'
sequence = unreal.load_asset(sequencer_asset_path)
input_file = 'D:/PretendDirectory/Animation/camera.fbx'

# Set camera's import options
def import_camera_FBX():
    import_options = unreal.MovieSceneUserImportFBXSettings()
    import_options.set_editor_property('create_cameras', False)
    import_options.set_editor_property('force_front_x_axis', False)
    import_options.set_editor_property('match_by_name_only', False)
    import_options.set_editor_property('reduce_keys', False)
    import_options.set_editor_property('reduce_keys_tolerance', 0.001)
    return import_options

# Find the camera bindings in the sequence
def camera_bindings():
    bindings = sequence.get_bindings()
    return bindings

# unreal.SequencerTools.import_fbx(world, sequence, bindings, import_fbx_settings, import_filename)
unreal.SequencerTools.import_fbx(world, sequence, camera_bindings(), import_camera_FBX(), input_file)

Ok, I’ve realised part of my mistake. unreal.SequencerTools.import_fbx() can be used to import animation onto anything, not just cameras, so it probably doesn’t read the focal length attribute at all (the create_cameras property threw me off). Must be something else happening when importing by right-clicking a camera in the sequencer.

I’ve been asking for a means to import focal length animation since forever, right now there is no way I know of that can make it work. I always resort to manually re-animating the Focal in sequencer.

Its too bad because sometimes you have complex camera moves in cut scenes and you need to be able to simply import that animation instead of trying to redo it in an approximate way.

Importing camera transform and focal length animation works for me. I usually import animation by right clicking the camera in my sequence and choosing Import (only works on Cine Cameras, not regular cameras). I’m hoping I can do this same import process through python, but can’t work out how.

is there a way to do this with python yet?

Hi, I recently figured out a way to import camera animation, including focal length:



import unreal

level_sequence = unreal.LevelSequence.cast(unreal.AssetToolsHelpers.get_asset_tools().create_asset(    
    asset_name='your_level_sequence_name',
    package_path='/Game/',
    asset_class=unreal.LevelSequence,
    factory=unreal.LevelSequenceFactoryNew()
))

cine_camera = unreal.EditorLevelLibrary.spawn_actor_from_class(unreal.CineCameraActor, unreal.Vector())
# Make sure your camera label is the same as in fbx file  
cine_camera.set_actor_label('ShotCam')  

binding = level_sequence.add_possessable(cine_camera)  
level_sequence.add_possessable(cine_camera.get_cine_camera_component())

camera_id = unreal.MovieSceneObjectBindingID()  
camera_id.set_editor_property('guid', binding.get_id())  
camera_cut_track = level_sequence.add_master_track(unreal.MovieSceneCameraCutTrack)  
camera_section = camera_cut_track.add_section()  
camera_section.set_range(0.0, 100.0)  
camera_section.set_camera_binding_id(camera_id)  

import_setting = unreal.MovieSceneUserImportFBXSettings()  
import_setting.set_editor_property('create_cameras', False)  
import_setting.set_editor_property('force_front_x_axis', False)  
import_setting.set_editor_property('match_by_name_only', True)  
import_setting.set_editor_property('reduce_keys', False)
import_setting.set_editor_property('reduce_keys_tolerance', 0.001)

world = unreal.EditorLevelLibrary.get_editor_world()  
unreal.SequencerTools.import_fbx(world, level_sequence, [binding], import_setting, 'your/path/to/fbx')


The point is that you need to add the camera component to LevelSequence possessables, and make sure there are keys on focal length in fbx file. SequencerTools.import_fbx function will add all the necessary tracks for you.

Hey, thanks for this. After reading your solution I was able to import focal length animation onto a possessable camera. I still can’t get it to import on a spawnable camera though, which is weird. I’m guessing it has something to do with the way sequencer binds things. If I query the binding for a possessable camera, it returns the camera component name. But when I query a spawnable’s binding, it returns the actor name.

Also, I found that you can actually config properties mapping between fbx camera and CameraComponent via Project Settings:

I guess you can even get film aperture or other camera properties through this way
Even better, you can map any ActorComponent properties to any custom properties in fbx objects

I think that’s a bug for UE4 Python? I do try use
binding = unreal.MovieSceneSequence.add_spawnable_from_instance(levelSequence, cine_camera.
get_cine_camera_component()), it didnt show error message but didnt do import cameraComponent in sequence neither? did anyone have any hint for this question?

Out of curiosity, has anyone tried to add a key to an editor property like camera_focal_length? I can set the value with this:
actor.camera_component.set_editor_property(‘current_focal_length’, 70.0)

However, I haven’t yet stumbled on how to set the key on specific frames. I am sure I am missing something extremely obvious.

had you find the way to solve the problem

Anyone found a solution for this yet?

When doing it manually you have to make sure that you have the sequence open and scrubbed at a position where the camera is spawned in the scene. Then import works correctly this way.

I tried to replicate this in python:



            unreal.LevelSequenceEditorBlueprintLibrary.open_level_sequence(sequence)
            unreal.LevelSequenceEditorBlueprintLibrary.set_current_time(start_frame)

            unreal.SequencerTools.import_fbx(world, sequence, [camera_binding], import_options, fbx_path)


But this doesn’t do what I want. Probably I need to force Unreal to do a Editor tick to actually create the camera in the scene and memory?

This trick here unfortunately does not work:
https://forums.unrealengine.com/development-discussion/python-scripting/1609614-is-it-possible-to-let-the-editor-tick-while-in-the-middle-of-a-script