I created an auto-save feature for Unity
Frustrated by the lack of any kind of auto saving feature for the Unity [game] editor, I decided to script my own. Hopefully in the future, this article will be obsolete.
12/30/20231 min read
We first start out by downloading auto hot key, which is just a simple scripting language that allows you to control GUI, clicks, buttons etc.
We’ll be sending the command Ctrl + S (simulating a save) to any open Unity programs (unity.exe).
When you have AHK downloaded, right click anywhere, and in the drop down menu go to New -> Autohotkey script (it can be edited in a simple notepad application)
The code looks like this:
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. ; #Warn ; Enable warnings to assist with detecting common errors. SendMode Input ; Recommended for new scripts due to its superior speed and reliability. SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory. #UseHook MsgBox, Starting autosave for unity. SetTimer, test, 5000 return test: ControlSend, , {ctrl down}s{ctrl up}, ahk_exe unity.exe return Esc::ExitApp
It’s a pretty straight-forward script.
First we set a timer for 5000 for testing purposes. 1000 is equal to 1 second, so for the recommended 10 minute auto save intervals, that value will be 600,000.
Then when that 10 minute mark arrives, we send Ctrl + S to any open unity editor programs.
That’s it! To get the files (any much more cool stuff) enter your email on the right side of the site.
Thanks for reading.