Search Unity

Intercept OnDisable

Discussion in 'Scripting' started by fwalker, Oct 13, 2020.

  1. fwalker

    fwalker

    Joined:
    Feb 5, 2013
    Posts:
    255
    Is there a way where I could intercept OnDisable, delay it enough to play an animation for the object to show it disappearing, then allow Unity to disable/deactivate the object?
     
  2. Deleted User

    Deleted User

    Guest

    Did you try just calling an animation.Play() method in OnDisable()?
     
  3. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,911
    You can't "intercept" disable. What you can do is instead of disabling the object, just play your animation, and create an Animation Trigger at the end of the animation that triggers code that finally disables the object.
     
    adamgolden likes this.
  4. fwalker

    fwalker

    Joined:
    Feb 5, 2013
    Posts:
    255
    Right... I forgot to mention, I want to do this when the user clicks the "disable" box on the editor ! :p
     
  5. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,911
    Not possible as far as I know. You could maybe spawn a new object and play a "fadeout" animation on that object, then destroy it. Seems like a lot of work for an editor feature though.
     
    Madgvox and Vryken like this.
  6. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
    Yeah, if this were a gameplay feature, it would be doable, but what's the point of doing something like this in the editor?
     
    PraetorBlue likes this.