OnSceneGUI requires you to be have the script open in inspector to work

So I’m using OnSceneGUI to get mouse position and mouse click within the scene view while the game plays and the only way it works is if I’ve selected the gameobject that the monobehavior script is attached to. Which gets annoying whenever you click on anything else because it suddenly stops working. Is this how OnSceneGUI is supposed to work and why does it work that way?

Well, you should look at the Tools class. If you want custom interactions in the sceneview, you should implement your own tool that the editor can switch to That’s what for example the Terrain editor does when you select a terrain object in the hierarchy and you start editing. You can set the current Tool to None or Custom depending on the exact usecase.

If anyone else is having this issue, you can use Selection to select an object in the hierarchy