My question: I believe I need to know the System Keyword for determining when a hotkey is pressed or when refresh is pressed, not just when processed. Anyone know this?
The reason:
Video of Problem that costs Unity devs thousands of hours of lost man hours each week:
People have told me there are only two options to compile:
- Let it auto refresh when code is changed and you tab to unity.
or
- Ctrl+r to refresh manually.
Let me explain why both of these options waste developer’s time.
Problems:
- Let it auto refresh when code is changed and you tab to unity…
Use Case: So you change code… But while coding, you wanted to see a number in the inspector about a game object to set as a variable. You alt tab to unity… It starts compiling. You need to wait 7 seconds. Then you get your number. You alt tab back to code and resume.
Net result: You lost 7 seconds of compile you didn’t need.
- Alternatively you could uncheck autorefresh, but this leads to worse problems since you need to Ctrl+r to refresh manually.
Use Case: You edit code, forget to ctrl+r before play. Then your game looks bugged still, so you edit code over and over for about 10 minutes then remember,“Oh yeah, Unity is forcing me to remember to ctrl+r” then you do that, revert a zillion changes, take another 5 minutes, and you’re wondering why you have “auto refresh?” checked.
Net result 15 minutes + wasted.
Solution: Give us an option to “Compile if needed when play button hit”, like every other sane IDE.
I asked this in another forum.
The solution was to uncheck refresh project on change of code, and add this script into your editor folder:
using UnityEngine;
using UnityEditor;
public class CustomEditorHelper : MonoBehaviour
{
[UnityEditor.Callbacks.DidReloadScripts]
private static void OnScriptsCompiled()
{
if (!Application.isPlaying)// && EnterPlaymodeAfterCompile)
{
EditorApplication.EnterPlaymode();
}
}
}
When I change code and alt -tab to editor, it doesn’t wait for compile, great!
When I hit ctrl+r to refresh, it refreshes and launches, great!
What it does not mimic of play/stop is:
-
Does not mimic stop play.
-
Does not allow launching the game with ctrl+r unless I change code.
My question: I believe I need to know the System Keyword for determining when a hotkey is pressed or when refresh is pressed, not just when processed. Anyone know this? If I knew when refresh hotkey was pressed, I could check if game running → stop. Or if code compiled → run anyway
OId code snippets on google do not get hotkey presses in editor, and This documentation doesn’t help either: Namespace UnityEditor