• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM [SOLVED] Object causes massive lag? (gms 1.4)

Dr_Nomz

Member
SOLUTION: DON'T use Game Maker's built in collision event! xD Just use the step event and try instance_place or place_meeting, that way if you comment it out it will actually STOP running the collision event. Also Pixelated Pope's comment below goes into detail as to why collisions can cause lag.

I don't know why, but for some reason one of my objects seems to take massive amounts of processing power and I have no idea what's causing it.

Basically I just create a bunch of objects that act as a GRID and they can change into other objects that are part of the "grid" for gameplay reasons.
GML:
Information about object: obj_Grid_Land
Sprite: spr_Grid_Land
Solid: false
Visible: true
Depth: 5000
Persistent: false
Parent: par_Grid
Children:
Mask:

No Physics Object
Create Event:

execute code:

global.grid_land += 1;

Mouse Event for Left Button:

execute code:

///Debug
/**/
global.grid_land -= 1;
instance_change(obj_Grid_Water,true);
^That's the ENTIRE code for it, here's the water grid:

GML:
Information about object: obj_Grid_Water
Sprite: spr_Grid_Water
Solid: false
Visible: true
Depth: 5000
Persistent: false
Parent: par_Grid
Children:
Mask:

No Physics Object
Create Event:

execute code:

global.grid_water += 1;

Collision Event with object obj_Grid_Land:

execute code:

/*with(other){
  instance_destroy();
}

Mouse Event for Right Button:

execute code:

///Debug
/**
global.grid_water -= 1;
instance_change(obj_Grid_Land,true);
And for some reason the water works just fine! They're not animated, they're only 50x50 px each. All they do is sit there and do nothing. They share the same parent but it doesn't do anything either. I KNOW it's the land because I tested with 100ish land and 200 ish water, had 600 FPS, changed all the land into water, and it was raised to like 3000! Any idea what's wrong? I can't figure out why it would be doing this at all.
 
Last edited:
Your reasoning is a little flawed. You removed all the land and assume it's the land that's causing problems. But your water has a collision event with land. So if you remove all the land, those collision events don't need to check for collisions with land, because there is none. I think it's the collision event. The more objects that you could "possibly" have a collision with, the slower that collision check is going to be. So if you consider how many water tiles you have, and each is checking a collision for EACH land tile (not really, but we don't need to get into the details of the fast collision system) you can do some quick math to get an idea of how many collision check operations you are doing every step.

I'm not gonna do that math, because I'm exceedingly lazy, but It is not a small number.
 

Dr_Nomz

Member
Yikes, using the build in function is a BAD idea. I'm doing manual checks in the Step event from now on, that way if I comment it out it'll actually stop it from checking the code lol.

Thanks dude, that was extremely helpful. BTW cool to see you still here! Your Data Structure tutorials are awesome, extremely flexible and useful. :D
 
Top