Search code examples
game-maker-studio-2game-maker-language

(GMS2) Spawner object doesn't spawn items


In GMS2 I have a spawner item with the following code:

  • In the create event:

    timer = 0;
    
  • In the step event:

    if(distance_to_object(obj_coffe_bean) > 2) 
        if(timer == 200) {
            instance_create_layer(x, y, obj_coffe_bean, obj_coffe_bean);
            timer = 0;
        }
    else timer++;
    

This works perfectly fine, coffee beans are spawned when it doesn't detect any coffee bean nearby.

The problem is that the same code doesn't work when I duplicate this object and create a spawner for another item.


Solution

  • Ok, I needed to use instance_create_depth instead of instance_create_layer.