# Python:Remove binding correctly in sequence

**URL:** <https://forums.unrealengine.com/t/python-remove-binding-correctly-in-sequence/482501>\
**Category:** Editor Scripting\
**Tags:** Python, binding, unreal-engine, sequence, question\
**Created:** [May 5, 2021, 6:14pm UTC](https://forums.unrealengine.com/t/python-remove-binding-correctly-in-sequence/482501 "2021-05-05T18:14:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tearcandy](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@tearcandy](https://forums.unrealengine.com/u/tearcandy)\
**Post date:** [May 5, 2021, 6:14pm UTC](https://forums.unrealengine.com/t/python-remove-binding-correctly-in-sequence/482501/1 "2021-05-05T18:14:18Z")

</div>

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.

 ![337204-broken-bound.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/a/6/1a603b5604e4cecc2f4b82b7ed6f8acb8e41885d.png)

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)
```

---

<div class="post-metadata">

**Author:** ![Markus68er](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Markus68er](https://forums.unrealengine.com/u/Markus68er)\
**Post date:** [October 13, 2022, 9:48am UTC](https://forums.unrealengine.com/t/python-remove-binding-correctly-in-sequence/482501/2 "2022-10-13T09:48:58Z")

</div>

Hi,

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

Best,

Markus

---

<div class="post-metadata">

**Author:** ![9Evgeny9](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@9Evgeny9](https://forums.unrealengine.com/u/9Evgeny9)\
**Post date:** [November 24, 2022, 4:15pm UTC](https://forums.unrealengine.com/t/python-remove-binding-correctly-in-sequence/482501/3 "2022-11-24T16:15:39Z")

</div>

> [@tearcandy](#):
>
> 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!

You must remove all tracks before removing main binding

```auto
  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()

```

---

<div class="post-metadata">

**Author:** ![smallbird](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@smallbird](https://forums.unrealengine.com/u/smallbird)\
**Post date:** [May 15, 2023, 10:31am UTC](https://forums.unrealengine.com/t/python-remove-binding-correctly-in-sequence/482501/4 "2023-05-15T10:31:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![smallbird](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@smallbird](https://forums.unrealengine.com/u/smallbird)\
**Post date:** [May 16, 2023, 2:38am UTC](https://forums.unrealengine.com/t/python-remove-binding-correctly-in-sequence/482501/5 "2023-05-16T02:38:21Z")

</div>

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