Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. We are looking for feedback on the experimental Unity Safe Mode which is aiming to help you resolve compilation errors faster during project startup.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Feature request: Refresh on play

Discussion in 'Editor & General Support' started by bennyer, Jul 8, 2019.

  1. bennyer

    bennyer

    Joined:
    Jan 16, 2017
    Posts:
    1
    I am a programmer and have been using Unity for over 4 years now. During my workflow I change both scripts and step to the Unity Editor to change stuff often. Because of this, I have turned off the auto refresh feature that compiles the changed scripts to save time (the refresh halts the editor gui during some time).

    This workflow makes me start my project in a two-step manner: first I have to refresh the project (ctrl+r) and afterwards start the project with the play button (or shortcut).

    Feature request:
    Alt 1 (preferred): Add a button, if auto refresh is off, next to the play button that performs a "refresh before play" .
    Alt 2: Add a boolean option in preferences "refresh on play".
     
  2. BluishGreenPro

    BluishGreenPro

    Joined:
    May 14, 2017
    Posts:
    5
    I second this; It's a feature I really liked when using GameMaker Studio
    Edit; Further, GameMaker provided the option to "Save, then Compile" on running, so that would be a nice option as well, since entering Play mode is one of the most frequent causes of crashes, so saving just before compiling and entering Play mode would save a lot of headaches
     
  3. DireLogomachist

    DireLogomachist

    Joined:
    May 29, 2013
    Posts:
    2
    For anyone else looking for a solution, I've created an editor script that does just this.
    Just drop this file as PlayRefreshEditor.cs in a top-level Editor folder and turn off Autorefresh in Edit->Preferences

    Code (CSharp):
    1. using UnityEditor;
    2.  
    3.  
    4. [InitializeOnLoadAttribute]
    5. public static class PlayRefreshEditor {
    6.  
    7.     static PlayRefreshEditor() {
    8.         EditorApplication.playModeStateChanged += PlayRefresh;
    9.     }
    10.  
    11.     private static void PlayRefresh(PlayModeStateChange state) {
    12.         if(state == PlayModeStateChange.ExitingEditMode) {
    13.             AssetDatabase.Refresh();
    14.         }
    15.     }
    16. }
    Your code and assets will be refreshed/recompiled after you press the Play button, instead of whenever you change focus to the Unity window. This was so annoying previously that I couldn't change focus to Unity without it being stuck for 4 seconds to refresh.
     
    drew55 and spryx like this.
  4. drew55

    drew55

    Joined:
    Dec 13, 2017
    Posts:
    24
    THANK YOU. This has been driving me INSANE and I was like someone has HAS to have made this script or else I'm in the wrong 3D engine or in the wrong community. <3
     
unityunity