Prevent Click thru GUI... I know, again

(noah) #1

I’m here again with this problem because I think that either I didn’t explain my problem right or maybe it got misunderstood. The issue is simple, if the action button (containing a skill) is over an NPC (or other object), if I click on the button, the NPC under/behind the button also gets clicked, and then the skill gets executed/activated. I don’t want the NPC to get selected (clicked)!
So here I go with the long explanation of the problem using a stripped-down project.

I opened a topic some time ago with pretty much the same tittle and I abandoned my efforts to fix it at that time because I thought I could “live with it”. But really, at this point it kills the fun and my patience and nobody can have a fluid gaming experience with that issue. Considering I’m not a programmer (That’s why I bought plyGame), I’ve followed videos that suggested me how to fix it, but nothing good from it. I’ve tried to implement some “short scripts” that have posted, but still, the basic concept is missing and not working. Then I come across my old post again and some other similar posts, where some answers simply state that if I’m using the sample/included UI (rpg_ui), I don’t have to do anything more to make it work, but I’m indeed using the sample UI and it is still not working. I’ve deleted and added again and again the script to the Execution order and still doesn’t work. Sorry if I’m bursting with words here but this issue is converting me in a “grumpy guy” cuz based on the other topics I shouldn’t be dealing with this issue.

I’ve stripped the project of all my stuff just to get to the bare core/basics of it and it’s simply annoying to note that the “order” of things happen exactly the other way around. I mean, I added debug notes to the different events, and the first thing that gets executed is the event from the object that was clicked thru… and then the event of the GUI button… Is my project cursed or something? If there was a simple way to copy/transfer all the prefabs (with the plybox stuff added), plus the spells, items, quests, etc., I would have started a project from zero to see if that works. But there’s no way to transfer that stuff, or is there a way?

Well, if you’re still reading at this point, maybe you want to help me out. I decided to create a blank project, and I only added plygame as package/assets to identify if my stuff was the one causing the problem or something else (Isolating the problem), followed the steps and got the problem again… why? :cry:

Here’s what I did:
1 - Created a new project and added plyGame
2 - Initialized plygame (it happens the first time you click this button)

3 - I configured a class and two attributes for that class (health,experience)

4 - I added a test skill (with only the event “On skill active” working, just a debug note to know it was activated)

5 - I Created a scene.
6 - Added a plane. Added an Sphere (as my Player). Added the player controllers, camera, actor, etc.(I can move the sphere with keyboard and mouse clicks) and I assigned the test skill to the player, slot 1 (or index 0)

7 - Added the sample_ui.unitypackage
8 - Added the two scenes (my main scene and the rpg_ui) to the plyGame project settings:

9 - I also added those to the Build settings (I made sure they were there already):

10 - I added a cube to the scene, to act as my NPC. I added a plybox and an event “On mouse down” with a debug note to it:

11 - I went to the rpg_ui to add an event to it, to have a debug note when it was clicked (even when we are gonna know it was clicked because the Skill was activated).

12 - I also made the button bigger and the whole area:

13 - And at last, I went to look at the Script Execution order to see what was there, and it was configured “the right way” as I’ve been reading in other posts:

So, it is time to test this “basic” scene to see what gets clicked first, and he’s an screenshot of the result:

And I click on the button/skill and this is the order:

What I was expecting is:
GUI button gets clicked
Skill gets activated… and that’s it! but no… the NPC got clicked too… why??? :sob:

I also made a short video of it, showing that the player (the sphere) moves with the click-to-move, so:

  • If the button is NOT over an NPC, the skill gets activated when the button is clicked and the “click-to-move” is not performed, and that’s good.
  • But if the button is over an NPC, the NPC “receives” the click and then the button gets the click and the skill gets activated…

Sorry for the level of frustration shown in this post, but my patience ran out.
Anyway, I hope somebody can give me an idea on how to fix it and preferable something already applied as a solution and not just a vague direction cuz most likely I’ll get lost along the way.


(Leslie Young) #2

The script execution order will only work for functions in the sample UI’s script. You made a custom button which is not making a call into the sample UI’s script but rather triggers a Blox event. The Blox event is running after whatever script handles character selection.

Try this first and if it does not work I can give other advice…

Grab latest extra blocks pack and add the Input > Input (plyGame) > Set Mouse Handled Block to your event.

Expand the Blox DLL and add plyBlox to execution order list. Easiest is to just drag and drop it there. Something like this…


(noah) #3

@leslie, it is not a custom button. It is the same button that comes with the sample UI (the first one of the action bar, index 0). I only increased its size for “presentation” purposes to make it easier to visualize in the video. And of course I added plybox to it just to add a debug label but the problem is the same without adding that label and without increasing it’s size. In other words it is exactly the action bar with the action buttons that comes with the rpg_ui… that’s why I created that empty project to avoid any “custom” stuff.

I’ll try what you mentioned about the extra blocks, even though I still don’t understand why do I have to do something extra when that specific part should be working out of the box according to the other posts that I’ve been reading.

I did what you said but still nothing good. I need to admit I wasn’t sure what you meant with adding the “Set Mouse Handled” block to my event… I wasn’t sure to what event. So, I did this first:

And then I added the “Set Mouse Handled” to the “buttonclicked” event of the action button but no difference, still clicking the NPC first, then the action button and then it executes the skill.
I added the “Set Mouse Handled” to the “On mouse down” event of the NPC (the green cube) but this doesn’t make sense, cuz if the event was triggered it means it was “clicked”. Anyway, it made no difference, and still the NPC gets clicked first. It is clear the intention of that block, to consume the click in one-first frame so it doesn’t affect anything else, but I was expecting that if I add that block to the “On mouse down” of the cube (NPC/Object) and since it is the first one executing stuff, I thought it would indeed consume the click but no, everything keeps getting “clicked”. Bottom line, it made no difference no matter if I placed that block in the action button, the NPC or the whole GUI area.
I even added that block to the whole action bar in the hopes to see something different in terms of clicks, anything, but nope, nothing changed. Like it is totally ignoring all those rules about handling the mouse clicks.

@leslie, maybe this would be “over the line” of the level of help you offer in the forums but, I can share the basic project with you of this example (it really has nothing other than the plane, the sphere (the player) and the cube (NPC/object)) and maybe you can look at it to see what’s the deal with it.

Either way, if you have some other idea, let me know please.

Thanks so much.

(Leslie Young) #4

The Blox you show threw me off and why I thought it was a custom button.

I see now what you are trying to illustrate. I thought the NPC was being selected by pyGame but you are only referring to the text appearing on the console “NPC clicked (GREEN CUBE)” . .right?

That “On Mouse Down” event is a Unity triggered event and totally disconnected from what plyGame controls around input.

Add an IF in that event with a check on the Input > Mouse Button Handled Block to see if UI consumed the input before doing anything else in there.

(Marshall Heffernan) #5


note: I used [NOT A] and then [Mouse Button Handled].



(noah) #6

It is fair to update about this. Long story short, I couldn’t make it to work out of the box mainly because of the order events happen.

Now the long story. First of all, the explanation about a click. A click can be seen as a on mouse up event, even when it has been an OnMouseDown event prior to that. So, the clicks over GUI elements, in this case on the action buttons are a combination of those two events, but more weight on the later (mouseUp). I added “on mouse down” events to my objects, so since the mouse down happens before the mouse up, that’s why it was “interacting” with the NPC’s first and then with the UI buttons.
Oddly, if I add an on mouse down event to the buttons, still the NPC’s catch first so no way to “flag” it as a mouse down on the button.

So, the solution I found was to turn a flag On/Off using the On Mouse Enter and On Mouse Exit respectively on the buttons, and that way if the mouse is over buttons, the flag is turned on and if the NPC’s receive a click they won’t interact with it cuz the flag is On. (For another odd reason the on mouse over event didn’t work either, so I had to use the Enter/Exit.