Author Topic: Clicking buttons inside Grid  (Read 18560 times)

smtabatabaie

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 13
    • View Profile
Clicking buttons inside Grid
« on: December 07, 2016, 03:16:28 PM »
Hi, I have a ScrollView which has a Grid which has some buttons inside it. the hierarchy looks like this :
-ScrollView
--Grid
---Button1
---Button2
---Button3
My buttons are instantiated at start and then I reposition Grid to sort the buttons inside my gird. The problem is I can't click my buttons unless I disable the collider of my grid. However if I don't instantiate my buttons and just have them normally inside my grid , I can click them without problem.
I'll appreciate if you can help me with this.
Thanks very much
Best

Holy Manfred

  • Jr. Member
  • **
  • Thank You
  • -Given: 1
  • -Receive: 8
  • Posts: 71
    • View Profile
Re: Clicking buttons inside Grid
« Reply #1 on: December 08, 2016, 09:16:43 AM »
Quote
The problem is I can't click my buttons unless I disable the collider of my grid.

I think your grid does not need to have a collider itself. It sounds like your touches get caught by a collider which is over your buttons. Did you try setting it up just using the colliders on your buttons and check the depth of each widget?

smtabatabaie

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 13
    • View Profile
Re: Clicking buttons inside Grid
« Reply #2 on: December 08, 2016, 09:19:20 AM »
Yes if I disable my grid's collider everything works fine, but if I do that I can't scroll in my scrollview

Holy Manfred

  • Jr. Member
  • **
  • Thank You
  • -Given: 1
  • -Receive: 8
  • Posts: 71
    • View Profile
Re: Clicking buttons inside Grid
« Reply #3 on: December 08, 2016, 10:21:26 AM »
It sounds like you might have the depth of some of your objects set wrong. Did you double check that the buttons you want to click have a higher depth than the background widget you use to drag the content?
Also, does your grid object have a UIWidget? If you just put a collider on the grid but now widget it can mess things up. Btw, you can turn on the debug option on the camera to see where your clicks are going.

smtabatabaie

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 13
    • View Profile
Re: Clicking buttons inside Grid
« Reply #4 on: December 08, 2016, 11:12:21 AM »
Thanks , No I have tried many different depth scenarios but none worked. What did work was to set the z-position of grid behind all other elements, at least in the editor. I hope it works the same in the mobile.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Clicking buttons inside Grid
« Reply #5 on: December 08, 2016, 07:15:22 PM »
Grid is not an object. Grid is a script. As such, it shouldn't have a collider. If you want a collider on your scroll view, you should instead add it to a background sprite. I usually set my scroll views like this:

Background Sprite (collider, drag scrollview script)
- Scroll view
-- Grid
---Items
---Items
---Items