Python:Remove binding correctly in sequence

I’m trying to remove binding which has no children and no bound objects. (but it still return True with “binding.is_valid()”)

As I know if binding lose bound objects then it turns to red in sequence like below image.

So I’m trying to remove this binding through following python command.

seq = unreal.load_asset("LevelSequence'/Game/Episodes/02/020270/Shots/0010.0010'")
    bindings = seq.get_bindings()
    for binding in bindings:
        if not binding.get_tracks() and not binding.get_object_template():
            binding.remove()

And I’m getting unreal editor crash.

Is this way right this kind of removing binding?

Please let me know if there is a right way.

Thanks in advance!

ps. I created spawnable cine camera this following code.

def buildCamera(shotData):
    cameraName = list(shotData.animFilePaths["cam"].keys())[0]
    shotSeqAsset = unreal.load_asset(shotData.shotSequence)
    cameraCutTrack = getMasterTracks(shotSeqAsset, unreal.MovieSceneCameraCutTrack)
    if not cameraCutTrack:
        cameraCutTrack = addMasterTrackToSequence(shotSeqAsset, unreal.MovieSceneCameraCutTrack)
    else:
        cameraCutTrack = cameraCutTrack[0]
    camBinding = None
    for binding in [x for x in shotSeqAsset.get_bindings()]:
        if binding.get_name() == cameraName:
            if not binding.get_tracks(): continue
            camBinding = binding
    if not camBinding:
        camBinding = addCameraToSequence(shotData, shotSeqAsset, cameraCutTrack)
    
    if not shotData.animFilePaths["cam"]:
        return
    if camBinding and shotData.animFilePaths["cam"]:
        for camName, animFilePaths in shotData.animFilePaths["cam"].items():
            importFbxToCamera(getEditorWorld(), shotSeqAsset, camBinding, animFilePaths[shotData.external]["fbx"])

def addCameraToSequence(shotData, seqAsset, cameraCutTrack):
    camName = "cam_" + shotData.seq + "_" + shotData.shot
    cameraCutSection = cameraCutTrack.add_section()
    cameraCutSection.set_range(shotData.startFrame, shotData.endFrame)

    cameraActor = unreal.EditorLevelLibrary().spawn_actor_from_class(unreal.CineCameraActor, unreal.Vector(0, 0, 0))
    cameraActor.set_actor_label(camName)
    cameraBinding = seqAsset.add_spawnable_from_instance(cameraActor)
    
    cameraComponent = cameraActor.get_cine_camera_component()
    cameraComponentBinding = seqAsset.add_possessable(cameraComponent)
    cameraComponentBinding.set_parent(cameraBinding)
    
    cameraBindingId = unreal.MovieSceneObjectBindingID()
    cameraBindingId.set_editor_property('Guid', cameraBinding.get_id())
    cameraCutSection.set_editor_property('CameraBindingID', cameraBindingId)

    focalLengthTrack = cameraComponentBinding.add_track(unreal.MovieSceneFloatTrack)
    focalLengthTrack.set_property_name_and_path('Current Focal Length', 'CurrentFocalLength')
    focalLengthSection = focalLengthTrack.add_section()
    focalLengthSection.set_start_frame_bounded(0)
    focalLengthSection.set_end_frame_bounded(0)
    
    manualFocusDistanceTrack = cameraComponentBinding.add_track(unreal.MovieSceneFloatTrack)
    manualFocusDistanceTrack.set_property_name_and_path('Manual Focus Distance (focus settings)', 'FocusSettings.ManualFocusDistance')
    manualFocusDistanceSection = manualFocusDistanceTrack.add_section()
    manualFocusDistanceSection.set_start_frame_bounded(0)
    manualFocusDistanceSection.set_end_frame_bounded(0)
    
    currentApertureTrack = cameraComponentBinding.add_track(unreal.MovieSceneFloatTrack)
    currentApertureTrack.set_property_name_and_path('Current Aperture', 'CurrentAperture')
    currentApertureSection = currentApertureTrack.add_section()
    currentApertureSection.set_start_frame_bounded(0)
    currentApertureSection.set_end_frame_bounded(0)
    currentApertureSection.get_channels()[0].set_default(2.8)
    
    filmBackWidthTrack = cameraComponentBinding.add_track(unreal.MovieSceneFloatTrack)
    filmBackWidthTrack.set_property_name_and_path('Sensor Width (Filmback)', 'Filmback.SensorWidth')
    filmBackWidthSection = filmBackWidthTrack.add_section()
    filmBackWidthSection.set_start_frame_bounded(0)
    filmBackWidthSection.set_end_frame_bounded(0)
    filmBackWidthSection.get_channels()[0].set_default(shotData.filmBack[0])
    
    filmBackHeightTrack = cameraComponentBinding.add_track(unreal.MovieSceneFloatTrack)
    filmBackHeightTrack.set_property_name_and_path('Sensor Height (Filmback)', 'Filmback.SensorHeight')
    filmBackHeightSection = filmBackHeightTrack.add_section()
    filmBackHeightSection.set_start_frame_bounded(0)
    filmBackHeightSection.set_end_frame_bounded(0)
    filmBackHeightSection.get_channels()[0].set_default(shotData.filmBack[1])

    transformTrack = cameraBinding.add_track(unreal.MovieScene3DTransformTrack)
    transformSection = transformTrack.add_section()
    transformSection.set_start_frame_bounded(0)
    transformSection.set_end_frame_bounded(0)
    
    cameraActor.destroy_actor()
    return cameraBinding

def importFbxToCamera(level, seq, camBinding, fbxFilePath):
    importSettings = getUserFbxImportSettings()
    unreal.SequencerTools.import_fbx(level, seq, [camBinding], importSettings, fbxFilePath)

Hi,

did you solve the editor crash issue? Having the same issue and trying to find a solution.

Best,

Markus

You must remove all tracks before removing main binding

  bound_objects = unreal.SequencerTools().get_bound_objects(world, level_sequence,level_sequence.get_bindings(), level_sequence.get_playback_range())
  for bound_object in bound_objects:
    if bound_object.binding_proxy.get_display_name()==('binding_name'):
        tracks=bound_object.binding_proxy.get_tracks()
        for track in tracks:
              bound_object.binding_proxy.remove_track(track)
        bound_object.binding_proxy.remove()
        unreal.LevelSequenceEditorBlueprintLibrary.refresh_current_level_sequence()

5.1 it works. but when i create a father sequence add them,the shots track doesnot work…

AHA~it’s my wrong, because cameracut binding wrong id~