- Home /
Which function gets called on Edit Mode when i select a GameObject?
It's a fairly simple question pls there's gotta be someone who knows it. I need to do some stuff whenever i select and let go of a GameObject on EditMode. Kinda like onEnable and onDisable, but on EditMode and i don't disable anything. Pls pls pls someone
Answer by KaspianR · Dec 05, 2019 at 10:05 AM
Ok, there are a few ways to do this and which one suits you best depends on how the rest of your code is setup! If you are writing a EditorWindow (or more specifically a class deriving from EditorWindow) fhe function OnSelectionChange()
will be called every time the selection changes (a.k.a. you select any object in the scene). The OnSelectionChange()
function can be used just as a normal Setup
or Draw
! You can also subscribe to Selection.selectionChanged
and the same thing will happen but this is not limited to EditorWindows. And the last approach I can think of is this: Implement ISelectHandler
in to your class and use the OnSelect
method. This will work if a script on the gameobject itself needs to get alerted when it is selected and therefore you will also not need to check if it's the same gameobject as the one you want to detect selection on! Hope one of these work and if it was a bit hard to grasp how to actually implement one of these I'm sure I or someone else will happily help you out with that! Good luck with your project!
Your answer
![](https://koobas.hobune.stream/wayback/20220612215724im_/https://answers.unity.com/themes/thub/images/avi.jpg)