This post is about resolving situations involving loosing parts of GameMaker projects - be that from human error, software glitches, or hardware failure.
This blog's share of reminding people about what's important.
The first thing to check would be if you have any backups.
- If you are using GMS1, backups are found in "My Documents\GameMaker\Backups" and are enabled by default.
- If you are using older versions of GameMaker, backups are found as .gb1...gb9 versions of the same file and may or may not be enabled by default.
- If you are using GMS2, there is no built-in mechanism for backups (so far).
As an additional note: prior to opening the backup(s), make an archive copy both of the backup and the broken current version, since running the backup version will overwrite the backup.
Restoring from temporary files
Little known fact: to display accurate code snippets in error messages and the debugger when the game is ran from IDE, GameMaker: Studio exports a special .yydebug file containing majority of the source code into a temporary directory.
While these are never generated for release builds, it means that your "temporary files" directory secretly contains multiple versions of complete source code of projects that you were developing.
Files can be found by searching for yourProjectName.yydebug in temporary directory. Temporary directory' path can be found on first page of preferences in GMS1 or under General Settings - Paths in GMS2.
Since .yydebug files use a purpose-specific binary format, decoding the file "by hand" wouldn't have been a particularly entertaining process, so I made a simple web-based program that you can load such a file into and view/copy any code contained inside:
Restoring from deleted files
If you had timely noticed disappearance of files (e.g. did that by yourself on accident), numerous programs exist to aid with process of recovering deleted files.
Personally I had some success with using MiniTool's software for data recovery on an occasion, but you are more than welcome to do your own research if the situation requires.
Restoring from final executables
While art/audio assets are relatively easily extracted, reconstructing source code into close-to-original format is a time-consuming process with high entry barrier, to the point where you may as well rewrite it from scratch anyway.
Pre-Studio versions of GameMaker included source code in compiled games, however, so could be generally decompiled (provided that you can find a tool for the according version used and did not use tools to prevent this from happening).
Once your recovery quest has ended (hopefully, successfully), it is a good time to consider taking steps so that you would not end up in the same situation in future.
For older versions, you can use gmk-splitter to convert the project files to and from format that can be versioned cleanly.
If you are absolutely against doing things properly, consider at least maintaining an up-to-date copy of project in cloud storage (e.g. Dropbox) so that files cannot be lost due to "local" issues alone.
Various approaches can be taken for recovering GameMaker projects, though ideally adequate measures should be taken to avoid ending up in such a situation to begin with.