Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

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

Discussion in 'Immediate Mode GUI (IMGUI)' started by S_Darkwell, May 3, 2018.

  1. S_Darkwell

    S_Darkwell

    Joined:
    Oct 20, 2013
    Posts:
    320
    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.
     
    oscarAbraham likes this.
  2. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    1,096
    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:
    320
    @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.