

This variable is then used to assign speed and direction to the new instance.
GAMEMAKER STUDIO 2 CHANGE INSTANCE LAYER CODE
The above code creates a new instance of the object obj_bullet in the "Instances" layer, and stores the instance ID in a variable. Var inst = instance_create_layer(x, y, "Instances", obj_bullet) OPTIONAL A struct with variables to assign to the new instance The object index of the object to create an instance of The layer ID (or name) to assign the created instance to The y position the object will be created at The x position the object will be created at

Instance_create_layer(x, y, layer_id, obj) Argument NOTE Variables from the struct are "shallow-copied" to the new instance, meaning any arrays, structs, and other resources are copied by reference and not duplicated. Built-in variables can be changed as well. Values applied to the new instance through this struct can be of any type, including method variables. This means that the values from that struct are readable in the Create event of the new instance. Variables from this struct are applied to the new instance before its Create event runs, but after its Variable Definitions are set. The last argument, var_struct, is optional and takes a struct containing additional variables for the new instance. Anything placed on a layer outside that range will not be drawn although all events will still run as normal. IMPORTANT There is a minimum and maximum layer depth of -16000 to 16000. Note that this function will also call the Create Event of the instance being created before continuing with the code or actions for the event that called the function. This function returns the id of the new instance which can then be stored in a variable and used to access that instance. The layer can be identified using the layer ID value (as returned by the function layer_create()) or by the name of the layer (as a string, for example "instance_layer") as defined in the room editor. With this function you can create a new instance of the specified object at any given point within the room and on the layer specified.
