• 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!

Windows [Solved]Unable to find any instance for object index

Sargonnas

Member
IDE v2.2.5.481
Rutime v2.2.5.378

When leaving any room, the game crashes because a generated object no longer exists. My object generation has worked flawlessly for months and I haven't changed any of those functions for some time. I just can't understand how this error is cropping up when I check that the object exists right before implementing the code. Apologies of my noobishness is blinding me here, I'm more of an artist than a programmer.

Important notes:
* Each of these troubled objects is the child of another object, which is created during the Init room and is persistent, if that matters.

* The error only occurs when leaving a room. The objects which GMS2 can't find on exiting the room do exist and work fine while inside the room.

* My most recent efforts in the game (some time before this error) have been with save systems, which caused me to parent all the problem objects to another for the purpose of saving. The code worked fine between rooms with the current version of the save system, but I'm including this because I feel its the most likely candidate. The save system I'm using is based on Shaun Spaulding's youtube tutorial: GameMaker: Better Saving & Loading
** The problem arises even when I don't save or load, so I'm not sure at all if my save system is at fault.

* The example listed below is not singular, any object I have which generates another during creation now causes this crash. And there are a lot.

The Code (in the main Step phase of the object):
Code:
if Gate != noone or Lights != noone or Engine != noone
{
    if action == "closed"
    {
        Gate.x = Gate.xclosed;
        image_speed = 0;
        activated = false;
        Engine.rumbling = false;
        Lights.image_index = 0;
        Lights.image_speed = 0;
    }
    if action == "open"
    {
        Gate.x = Gate.xopen;
        activated = false;
        image_speed = 0;
        Engine.rumbling = false;
        Lights.image_index = 0;
        Lights.image_speed = 0;
    }
}
The Error:
___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Step Event0
for object oLoche:

Unable to find any instance for object index '104553'
at gml_Object_oLoche_Step_0 (line 80) - Lights.image_speed = 0;
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Object_oLoche_Step_0 (line 80)
 

TsukaYuriko

☄️
Forum Staff
Moderator
Comparing an instance/object reference to noone does not constitute checking whether it exists (unless you're getting these as return values from a function that returns instance IDs or noone).

Calling instance_exists checks whether instances exist.


Also, you're linking those conditions together via or. That means the following code will run if any, but not necessarily all of them, exist.
 

Hyomoto

Member
To add a little to this conversation, all objects that are not persistent are removed when the room ends. Persistent objects on the other hand do not "exist" during the cleanup event. They are, presumably, moved "somewhere safe" during the room transition and become available again in the next room during the create event.

That said, your bug seems to be that you are saving the actual instance id. While it is possible to have GM create things in the same order each time the program is run, it's a bit like a speedrunner manipulating RNG: any deviation or change will result in an unknown state. In this case, whatever "Engine" is supposed to be may exist, but instance id '104553' does not. Therefore your issue is that the instance you are saving does not exist (which makes sense, the room ended). When it comes to saving objects, and preserving their state, you need to save the `object_index` and the values attached to it so it can be recreated and configured when the game/room begins.
 

Sargonnas

Member
Comparing an instance/object reference to noone does not constitute checking whether it exists (unless you're getting these as return values from a function that returns instance IDs or noone).

Calling instance_exists checks whether instances exist.


Also, you're linking those conditions together via or. That means the following code will run if any, but not necessarily all of them, exist.
To add a little to this conversation, all objects that are not persistent are removed when the room ends. Persistent objects on the other hand do not "exist" during the cleanup event. They are, presumably, moved "somewhere safe" during the room transition and become available again in the next room during the create event.

That said, your bug seems to be that you are saving the actual instance id. While it is possible to have GM create things in the same order each time the program is run, it's a bit like a speedrunner manipulating RNG: any deviation or change will result in an unknown state. In this case, whatever "Engine" is supposed to be may exist, but instance id '104553' does not. Therefore your issue is that the instance you are saving does not exist (which makes sense, the room ended). When it comes to saving objects, and preserving their state, you need to save the `object_index` and the values attached to it so it can be recreated and configured when the game/room begins.
Wow! I guess that's the trouble with using so much borrowed code you don't understand. Using instance_exists did the trick! I'm not sure why the problem cropped up now all of a sudden, but its all working now!

Strangely, switching those statements has since made my character animations stop animating. This programming thing is truly mystifying sometimes.

Thanks guys!
 
Top