GMS 2 Object disappearing [SOLVED]

I just want to post this in case anybody else has the same problem.

I had an object disappearing for seemingly no reason. I wasn't destroying it or changing rooms. It just stopped running. By checking to see if it still existed, I realized it didn't! In my search for an answer I came across this archived thread on Reddit:

https://www.reddit.com/r/gamemaker/comments/6akx7u/gms2_object_disappearing_for_no_reason/

The user "damimp" suggested said:

It seems like there may be something up with your object's position in the resource tree. Consider code like this:
Code:
with(0){
   instance_destroy();
}
If something like this were floating around somewhere, it would cause the first object in the resource tree to delete itself.
Sure enough, I had this code destroying an unrelated object, or so I thought:
Code:
instance_destroy(global.itemAtGameStart[i]);
It was destroying my game controller object in the first position of the resource tree!

A simple check put an end to a bug that has been bothering me for ages!

Code:
if (global.itemAtGameStart[i] != 0) { instance_destroy(global.itemAtGameStart[i]); }
If you're out there, damimp, thank you!
 
Top