Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Let us know a bit about your interests, and if you'd like to become more directly involved. Take our survey!
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Detect Unity Editor Step Button Click Without Using of Unity's Time Class?

Discussion in 'Extensions & OnGUI' started by S_Darkwell, May 3, 2018.

  1. S_Darkwell

    S_Darkwell

    Joined:
    Oct 20, 2013
    Posts:
    292
    Hello!

    How would I detect use of the Unity editor's "Step" button/menu item/keyboard shortcut without use of Unity's Time class?

    I have created a custom PlayerLoop to allow for the manual triggering of script Update() methods. I am trying to identify when the Unity Editor's "Step" method has been called to trigger so as to manually trigger Update() methods when that occurs. My custom PlayerLoop does not include Unity's native Initialization.PlayerUpdateTime PlayerLoopSystem, which prevents Unity's Time class from being updated and thus renders variables such as Time.frameCount useless.

    Currently, I am using Application.isPlaying && !EditorApplication.isPaused to prevent the PlayerLoop from updating scripts when the editor is not playing/paused, but this also prevents the "Step" method from working.

    For reference, I am seeking to code this in C#, and I am using Unity v2018.2.0b2 with the Scripting Runtime Version ".NET 4.x Equivalent".

    Any assistance with solving this challenge is much appreciated!

    Thank you in advance, and be well!

    - S.
     
  2. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    394
    The reverse engineered code of the step-button looks like this:
    Code (CSharp):
    1.             if (GUILayout.Button(Toolbar.s_PlayIcons[num + 2], "CommandRight", new GUILayoutOption[0]))
    2.             {
    3.                 EditorApplication.Step();
    4.                 GUIUtility.ExitGUI();
    5.             }
    So, it calls
    EditorApplication.Step()
    which is an external method (no C#). There is no callback or something anywhere so I think it is not possible to detect it.

    However: you can create your own step button where you call
    EditorApplication.Step()
    .
     
    S_Darkwell likes this.
  3. S_Darkwell

    S_Darkwell

    Joined:
    Oct 20, 2013
    Posts:
    292
    @Hosnkobf:

    Thank you for your response!

    Alas, I was afraid that there might not be a way to detect that action specifically. I wonder, though--is there a way to hijack Unity's default button behavior? If so, I could simply re-implement the Step() function in a way that exposes the needed functionality. I know some plugins are able to overwrite at least some default Unity behaviors, such as Console extensions that hijack the functionality of clicking on the bottom status bar. Is this something with which you are familiar or have any ideas/helpful hints?

    I realize that I could always simply create an additional toolbar that works as I want, but the idea of having duplicate sets of play control buttons is unpleasant to me.

    Thank you again/in advance! Be well!

    - S.