Set focus method of spawned camera

In Unreal engine 5.8 I have tried to set the focus method of a spawned camera (in a level sequence) using the python API but nothing seems to work. Could you provide a snippet how this could be achieved?

[Attachment Removed]

Steps to Reproduce

In Unreal engine 5.8 I have tried to set the focus method of a spawned camera (in a level sequence) using the python API but nothing seems to work. Could you provide a snippet how this could be achieved?

[Attachment Removed]

Hey there,

Yep I can provide that.

import unreal
 
# Get a camera, below I make one.
# Get the subsystem
ls_subsystem = unreal.get_editor_subsystem(unreal.LevelSequenceEditorSubsystem)
camera_binding, camera_actor = ls_subsystem.create_camera(spawnable=True)
 
#Get the camera's cine camera component
comp = camera_actor.get_cine_camera_component()
#Get the focus settings.
focus = comp.focus_settings
 
#modify them using the unreal.CameraFocusMethod, Options are TRACKING, MANUAL, DISABLE, DO_NOT_OVERRIDE
focus.focus_method = unreal.CameraFocusMethod.TRACKING
 
#Set them back to the component
comp.set_editor_property("focus_settings", focus)
 
# You'll want to probably do this to the template object in sequencer as well. 
# All of the functions are the same but when you get the camera you'll also want 
# to get the template object.
template = camera_binding.get_object_template()

Hope this helps you out,

Dustin

[Attachment Removed]

Hi,

Thank you for your quick reply.

However, my issue is that I get None when I try to get the CineCameraComponent.

What I need to do is to get the CineCameraComponent of an existing camera in a LevelSequence. I do not create the camera and then immediately try to get the component, instead I open up an existing sequence with an already created, spawnable camera and from that one try to get the camera component (to be able to set the focus method)

Below is a snippet of the script I am using:

seq = unreal.LevelSequenceEditorBlueprintLibrary.get_current_level_sequence()
 
for binding in seq.get_bindings():
 
    obj = binding.get_object_template()
    if not isinstance(obj, unreal.CineCameraActor):
        continue
    
    cine_camera_component = obj.get_cine_camera_component()
 
    print(obj)
    # Result -> <Object '/Game/spawnable_cam/LS_spawnable_cam.LS_spawnable_cam:MovieScene_0.CineCameraActor_1' (0x00000204CDBC2A00) Class 'CineCameraActor'>
    print(cine_camera_component)
   # Result -> None 
 
    ...

I get the CineCameraActor but when I try to get the component I get None?

What am I missing?

Thank you,

Regards,

Johan

[Attachment Removed]

Hey there,

Bindings can be tricky as well. When you get bindings you don’t just get a top level array, you’ll get all kinds of different things, and not every binding has an object template. Object Template are for spawnables only. So in your case above if for any the camera is not actually spawned or is not a spawnable, but is instead a possessable, this would fail. Also get_current_levelsequence can fail if you’re not working on the top level sequence but instead a subseqeunce. Overall a safer approach might be something like:

import unreal
 
lib = unreal.LevelSequenceEditorBlueprintLibrary
 
# Read bindings from the sequence Sequencer is actually focused on
seq = lib.get_focused_level_sequence()
 
for binding in seq.get_bindings():
    binding_id = seq.get_binding_id(binding)
    objs = lib.get_bound_objects(binding_id)
    for obj in objs:
        #note i'm checking the camera component here, a binding could be the component already.
        if not isinstance(obj, unreal.CineCameraComponent):
            continue
 
        obj.focus_settings
        #etc
 

[Attachment Removed]

Hi Dustin,

Thank you so much!!!

The only thing I added was to mark the object as “dirty” to be able to save the edit.

obj.modify()
obj.set_editor_property('focus_settings', fs)

[Attachment Removed]