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. 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. This function returns the id of the new instance which can then be stored in a variable or used to access that instance. 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.IMPORTANT! There is a minimum and maximum layer depth of -16000 to 16000. Anything placed on a layer outside that range will not be drawn although all events will still run as normal.
instance_create_layer(x, y, layer_id, obj);
|x||The x position the object will be created at|
|y||The y position the object will be created at|
|layer_id||The layer ID (or name) to assign the created instance to|
|obj||The object index of the object to create an instance of|
Real (instance ID value)
var inst = instance_create_layer(x, y,
speed = other.shoot_speed;
direction = other.image_angle;
The above code creates a new instance of the object "obj_Bullet" and stores the instance id in a variable. This variable is then used to assign speed and direction to the new instance.