User avatar
Scherub
Topic Author
Posts: 141
Joined: 06 May 2014, 20:53
Contact:

[Unity] Click through

25 Aug 2014, 20:32

Hello,

I've a question regarding click through. Until now it hasn't really been a problem as most of my current gui stuff were just tests for several game component tests. But now that various game components come together I finally created various user controls that I integrated into my game world. The problem that occurs now is that when I click a button I also interact with my game world.

I found your solution with the hit test that you have to apparently add to any interactive game object. The thing is that I have hundreds of interactive game objects and I really don't want to put this logic there.

So is there a better solution to this?
 
movra
Posts: 70
Joined: 02 Apr 2014, 20:35

Re: [Unity] Click through

26 Aug 2014, 01:22

I wonder if Unity 4.6's Event System makes a difference. There are new interface-based events such as OnPointerClick(PointerEventData data). You can look up the manual included with 4.6, Editor/Data/Documentation/html/en/Manual/EventSystem.html

In the Widgets scene from the example project you can move the button on top of the bunny. Pressing the button doesn't trigger the OnPointerClick event on the bunny.
 
User avatar
jsantos
Site Admin
Posts: 3905
Joined: 20 Jan 2012, 17:18
Contact:

Re: [Unity] Click through

26 Aug 2014, 15:38

We are open to suggestions here. The event architecture in Unity is very weak to solve this properly. We cannot cancel events. For now the best solution could be having a base class that does all the filter for you (the HitTest code). Then you can inherit from this class instead of MonoBehaviour.

What do you think?
 
wckdspn
Posts: 67
Joined: 18 Aug 2012, 23:14

Re: [Unity] Click through

28 Aug 2014, 02:13

I manage my own Input management class which classes subscribe to instead of Unity directly. Gives me more granular control, and also acts as a user-remappable action table.
 
User avatar
Scherub
Topic Author
Posts: 141
Joined: 06 May 2014, 20:53
Contact:

Re: [Unity] Click through

03 Sep 2014, 16:10

Thank you all for your hints and tips.

I don't think Unity's new event system will make a big difference tbh, at least not from what I saw when I glanced over it.

The solution for me at the moment is that the behaviour that is responsible for setting up Noesis and the main view model also queries every update cycle whether the current mouse position is over a gui element or not and write the result in a property. Then instead of the game objects itself another class just sends a ray to see whether an interactive game object was hit. It then queries the property from the Noesis Gui Behaviour whether we're over an UI element and if not it will notify the game object.

So this works for MouseOver as well as MouseClick. Of couse it doesn't work with touch and multiple inputs for now. It's just a start and I'm also working on my own more flexible input system with a few events where I can hook into.

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 66 guests