How to disable buttons covered up by other ones on same layer

I am making a game where tokens and cards will be able to be dragged out onto a playing area and clicked. They may need to be overlapped sometimes but it dont want clicking on one to activate all of them. they also need to stay visible. I know the draggable behavior automatically blocks objects underneath but button does not. how can i implement this?

1 Like

You can put your buttons on different layers

And simply by checking if layer is visible disable buttons on layer below that layer

1 Like

@ZeroX4
My game will have many objects out at once that need to stay visible. so i didnt want to do layers .i was hoping i could use z order somehow to figure out the top object under the cursor. there may be multiple different objects under the cursor at once that it needs to take into account.

1 Like

Then

Look you should make scene variable call it TopPick

When nothing is clicked set it to 0
When something is clicked set it to that object Z order (so you need to put all these objects into same group let’s call it Buttons)
But add condition
Buttons Z order is greater than variable TopPick

This way if variable is 0
And you click on 2 buttons one with Z order 15 other with Z order 22
If 2nd button got picked 1st (on with z order 22) then 1st one (one with z order 15) will not be able to overwrite TopPick variable

If 1st first button will be picked (one with 15 z order) it will overwrite variable but as soon as 2nd will be picked (one with 22 z order) it will overwrite TopPick variable

And now you can make event
Object Z order NOT EQUAL to TopPick

Disable button behavior
Or simply add that condition to however you manage buttons

And only thing left to do is to reset TopPick to 0 when nothing is pressed
And enable back buttons behavior if you disabled any

You will need to do some tests cause i think it may need need repeat for each but i am not sure about it

But that will be easiest way i can think of doing it

You could put them in a group and then use pick nearest object from the cursor x and y. You could use the Object picking tools extension to pick the object with the highest or lowest Z. Be careful bc it will pick all of the objects with the highest or lowest Z so either be sure to use unique Z values or also use the pick nearest afterwards.

You could also use a mouse is on button or point is inside to move the object underneath the cursor to the top either permanently or temporarily. You could use a higher layer and move the object to that layer when the cursor is over it.

You could create a sort of x-ray effect and change the opacity or blend style of objects that overlap. Or maybe use an object outline or just an outline of the object on a higher layer of the object under the cursor.

There are numerous ways to give the user visual clues as to which object will be used.