Search Unity

  1. Full schedule for #UniteBerlin is now available! Featuring talks on our roadmap, hands-on labs and much more! Check it out!
    Dismiss Notice
  2. Unity 2018.1 has arrived! Read about it here
    Dismiss Notice
  3. Scriptable Render Pipeline improvements, Texture Mipmap Streaming, and more! Check out what we have in store for you in the 2018.2 Beta.
    Dismiss Notice
  4. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  5. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  6. 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:
    288
    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:
    180
    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:
    288
    @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.