sequence_instance_override_object

With this function you can override (replace) all instances of an object used in a sequence with another one or override a single instance of an object with an existing instance.

You supply the sequence instance struct ID (as returned when the sequence instance was created in the room or by using one of the room layer functions - see here), as well as the object index (as defined in the asset browser) for the object that you want to override. Finally you give an object index or an instance ID to use as the object that is going to override the sequence (supplying an instance ID will simply use the object that the instance was created from as the override). Note that this can only be done on sequence instances (not sequence objects) and must be done before the sequence starts to play, otherwise it won't work.

IMPORTANT If you use this function with a sequence instance that has multiple object tracks of the same object asset and you provide an instance ID as the second argument then only the first instance is replaced with the given instance. The other object tracks will not get an instance.

IMPORTANT If you provide an existing instance ID the instance will stay on the layer it is already on. The instance isn't moved to the layer that the sequence instance/element is on. This is different from creating a sequence instance on a layer using layer_sequence_create, where all instances are added to the layer with the sequence element.

Syntax:

sequence_instance_override_object(sequence_instance_struct, object_id, instance_or_object_id);

ArgumentTypeDescription
sequence_instance_structSequence Instance StructThe sequence instance struct to modify.
object_idObject AssetThe object index of the object within the sequence to override.
instance_or_object_idObject Asset or Object InstanceThe object index or instance ID to use to override the sequence objects.

 

Returns:

N/A

 

Example 1: Replace an object ID with another object ID

var _seq = layer_sequence_create("Background", 0, 0, seq_AnimatedBackground);
var _seq_inst = layer_sequence_get_instance(_seq);
sequence_instance_override_object(_seq_inst, obj_Trees_Winter, obj_Trees_Summer);

The above code creates a new sequence instance on the given layer and then modifies it so that all instances of the object "obj_Trees_Winter" are replaced by instances of the object "obj_Trees_Summer".

Example 2: Replace the first instance of an object ID with an instance ID

var _seq = layer_sequence_create("Background", 0, 0, seq_AnimatedBackground);
var _seq_inst = layer_sequence_get_instance(_seq);
var _inst = instance_find(obj_Tree_Christmas, 0);
if (_inst != noone)
{
    sequence_instance_override_object(_seq_inst, obj_Trees_Winter, _inst);
}

The above code creates a new sequence instance on the "Background" layer. It then tries to find an instance of "obj_Tree_Christmas" using instance_find. If an instance of this object is found it then replaces the first instance of object "obj_Trees_Winter" in the sequence by this instance using sequence_instance_override_object. All other object tracks with "obj_Trees_Winter" as the object will not have an instance.