How to add spoiler tags, edit posts, add images etc. How to - a user's guide to the new version of Boards
Mods please check the Moderators Group for an important update on Mod tools. If you do not have access to the group, please PM Niamh. Thanks!

Game Maker: Game crashing when collision happens.

  • #1
    Registered Users Posts: 101 ✭✭ PKdude

    Hey, I'm trying to make it so that when 2 objects collide, one gets destroyed while the other remains. I've almost done that, but as soon as the objects collide, the game crashes. I am unsure why, and I haven't experienced this before. So if someone could even just point me in a good direction, that would be appreciated.

    This is the collision event on one object ("EnemySpaceship"), and ties to the other object ("Spaceship1"). I have a drag and drop action to "Destroy the Instance", and then another action of code which is:

    EnemySpawn.dead = true;

    Then I have an object called "EnemySpawn" which sorts the spawning for the enemy. It has a Create event with the code:

    instance_create(x,y, EnemySpaceship)

    It also has an Alarm event with the code:

    instance_create(x, y, EnemySpaceship);

    And finally it has a Step event with the code:

    if dead = true
    alarm[0] = 60
    dead = false

    The error that comes up says:

    action number 2
    of Step EventSpaceship1
    for object EnemySpaceship:

    Unable to find any instance for object index '2' name 'EnemySpawn'
    at gml_Object_EnemySpaceship_CollisionEvent_0_2 (line 1) - EnemySpawn.dead = true;"

    I think that's all I can supply for it, Thanks for taking the time to look at it.


  • What's happening is you are destroying the object but the code running after that event is now looking for that object that isn't there anymore. That's causing the crash. You need to stop that code after the destroy event.