room_instance_add

This function adds an instance into any room other than the current one at any position within that room.

The function returns the unique id of the instance which can then be used in further function calls to set properties, etc. of that instance, but only once the game has entered the specified room. If you wish to create an instance in the current room you should be using the function instance_create_layer.

NOTE Calling this function on a room asset created in The Asset Browser will permanently add the instance to the room, and even calling game_restart will not return the room to its original state. Only ending the game and opening it again will start with the room in its original state again.

 

Syntax:

room_instance_add(index, x, y, obj);

ArgumentTypeDescription
indexRoom AssetThe room to add an object instance to.
xRealThe x position of the new instance.
yRealThe y position of the new instance.
objObject AssetThe object to add an instance of.

 

Returns:

Object Instance

 

Example:

global.rm = room_add();
room_assign(rm_base, global.rm);
room_instance_add(global.rm, 100, 100, obj_player);

The above code will add a new room to the game and then copy the contents of the room indexed as rm_base into it. It will then add an instance of the object obj_player at the position (100, 100) of this new room.