• Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Question - Code How do I change what layer an instance is on in GML?

hdarren

Member
When I create an instance using "object = instance_create_layer()" how do I later change what layer that instance is on?
 

Baku

Member
Change the instance's layer variable directly, or use layer_add_instance()

Code:
object.layer = layer_get_id("LayerName");
// or
layer_add_instance(layer_get_id("LayerName"), object);
Read the manual, dude ;)
 

hdarren

Member
That is good.

So now I can create a script called instance_create(x,y,object) which creates a instance_create_layer(x,y,default_layer,object) then in the Create event of the object I set layer=layer.

This means my code is much tidier and if happen to change layer name or what layer object should be on I don't need to change a million bits of code. :)
 

rwkay

GameMaker Staff
GameMaker Dev.
you could also just use instance_create_depth() as an object no longer has a depth variable so you cannot set the depth of the object and every instance inherits it as that was silly - you now create the instance at a set depth (a layer will be auto created for you at that depth)....

Personally I would just swap to instance_create_depth() if you are not using layers directly.

Russell
 
F

Falconsoft-Industries

Guest
Could the same be done with the layers in the object editor and room editor for specific instances? Let's say I am making a isometric RPG, how would I go about isometric depth? Now that was just an example, for references to asking for help on assigning instances to individual instance layers. ;)
 
Top