Home

Awesome

DuplicateSequence.gml

Donate License

In GameMaker currently, there is no built-in way to modify sequences in runtime without modifying the main sequence resource. This function is aimed to fix this issue, so you can create a duplicate of your sequence resource, modify its properties and spawn a new sequence instance without breaking the original one. This also may be useful for serialization purposes.

This is a collection of scripts providing a simple way to deep copy sequences and sequence fields in your GameMaker projects. Deep copying ensures that a new independent copy of a sequence is created, allowing you to modify and manipulate the copy without affecting the original sequence. It allows you to copy sequences itself, as well as keyframes, keyframe data and tracks separately.

One of the use cases of modifying sequences in runtime is, for example, creating a layout for UI button / resource art / character animation with placeholder images and text in the IDE, and then change it with the final ones for each instance before sending them on screen.

<p align="center"> <img src="https://keevee.games/wp-content/uploads/2023/06/sequence_duplicate_o.gif" alt="Example GIF"> <br><sub>notice how the modification of sequence properties (tank's sprite) is also altering<br>the originally spawned sequence on the left, which is not happening with sequence_duplicate</sub> </p>

Example:

layer_sequence_create(layer, 400, 200, seq_test);                   // place original sequence in game

var seq_new = sequence_duplicate(seq_test);                         // create sequence duplicate
seq_new.tracks[0].keyframes[0].channels[0].text = "Hello World";    // change new sequence's property
// this will not change the original sequence property!

layer_sequence_create(layer, 400, 400, seq_new);                    // place new sequence in game

Installation:

Copy the script into your project.
Or get the latest asset package from the releases page and import it into IDE.

Reference:

sequence_duplicate(sequence_struct_or_id)Struct.Sequence

This function will return a new sequence struct that is a deep copy of the source sequence.

Parameters:

NameTypeDescription
sequence_struct_or_idAsset.GMSequence or Struct.SequenceThe sequence index from the asset browser or sequence object struct

Returns: Struct.Sequence

<details> <summary><h3>Additional functions</h1></summary>

sequence_keyframes_duplicate(keyframes, type)Struct.Keyframe[]

This function will return a new array of keyframes with deep copies of source keyframes.

Parameters:

NameTypeDescription
keyframesStruct.Keyframe[]The source array that holds keyframe structs of a sequence
typeConstant.SequenceTrackTypeThe type of track that keyframes are applied to, a seqtracktype constant

Returns: Struct.Keyframe[]

sequence_keyframe_duplicate(keyframe_struct, type)Struct.Keyframe

This function will return a new keyframe struct that is a deep copy of the source sequence keyframe.

Parameters:

NameTypeDescription
keyframe_structStruct.KeyframeThe track keyframe struct to duplicate
typeConstant.SequenceTrackTypeThe type of track that the keyframe is applied to, a seqtracktype constant

Returns: Struct.Keyframe

sequence_keyframedatas_duplicate(keyframedatas, type)Struct.KeyframeData[]

This function will return a new array of keyframe data with a deep copy of the source keyframe data

Parameters:

NameTypeDescription
keyframedatasStruct.KeyframeData[]The source array that holds keyframe data structs of a sequence
typeConstant.SequenceTrackTypeThe type of track that the keyframe is applied to, a seqtracktype constant

Returns: Struct.KeyframeData[]

sequence_keyframedata_duplicate(keyframedata_struct, type)Struct.KeyframeData

This function will return a new keyframe data struct that is a deep copy of the source keyframe data struct.

Parameters:

NameTypeDescription
keyframedata_structStruct.KeyframeDataThe keyframe data struct to duplicate
typeConstant.SequenceTrackTypeThe type of track that the keyframe is applied to, a seqtracktype constant

Returns: Struct.KeyframeData

sequence_tracks_duplicate(tracks)Struct.Track[]

This function will return a new array of tracks with a deep copy of the source tracks.

Parameters:

NameTypeDescription
tracksStruct.Track[]The source array that holds track structs of a sequence

Returns: Struct.Track[]

sequence_track_duplicate(track_struct)Struct.Track

This function will return a new track struct that is a deep copy of the source track struct.

Parameters:

NameTypeDescription
track_structStruct.TrackThe track struct to duplicate

Returns: Struct.Track

</details>

Authors:

Nikita Musatov - MusNik / KeeVee Games

Contributors:

License: MIT