Author Topic: Button don't detect input if parent change position on-screen? [SOLVED]  (Read 2548 times)

vexe

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 153
    • View Profile
I'm having a really weird issue: I have an inventory system with slots instantiated at run-time via a slot/button prefab.
My Anchor is set to topleft. Everything works as expected when I run in maximized mode. However, if I change the inventory position OR run in normal non-maximized view, some if not all the buttons will not detect input at all! Nothing will happen if I hover over them, etc. Although I checked to see if something went wrong with the slots after I moved the bag/inventory, everything is still set right, the colliders, etc. See the images in the attachment.

I created a simple button and changed its anchor, played around with its position in both normal and maximized views, it worked OK, which means it must be a problem with my slot prefab... However, it seems like it's a normal button, see the inspector image I provided as well :/

Please help, I'm really puzzled here... Thanks.

EDIT: If you want to see the code for instantiating:
  1.         public void AddSlot(int i, int j)
  2.         {
  3.                 GameObject slotObj = NGUITools.AddChild(gameObject, slotTemplate);
  4.                 Transform slotTrans = slotObj.transform;
  5.                 float x = SPACE_BETWEEN_SLOTS * (j + 1) + j * slotSize;
  6.                 float y = -SPACE_BETWEEN_SLOTS * (i + 1) - i * slotSize - headerPadding;
  7.                 slotTrans.localPosition = new Vector3(x, y, 0f);
  8.                 var slot = slotObj.GetComponent<Slot>();
  9.                 slot.Init(new Index2D(i, j), new Dimension2D(x, y), slotSize);
  10.                 slots[i].Add(slot);
  11.         }
  12.  
« Last Edit: August 19, 2013, 10:28:38 PM by vexe »

vexe

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 153
    • View Profile
Re: Button don't detect input if parent change position on-screen?
« Reply #1 on: August 14, 2013, 04:24:54 AM »
In the inventory example, I saw the usage of Bounds and bound.Encapsulate, I'm not sure if this is relevant here or not...

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Button don't detect input if parent change position on-screen?
« Reply #2 on: August 15, 2013, 07:43:26 AM »
Easiest way to tell what's under the mouse is to enable debugging on the UICamera.

vexe

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 153
    • View Profile
Re: Button don't detect input if parent change position on-screen?
« Reply #3 on: August 19, 2013, 12:53:12 PM »
THANKS!!! that helped a lot, you were right, there was something invisible intersecting/on the way of the camera, however the strange thing was 'that something' is from another layer, other than the camera's culling mask (belongs to another 2D layer, which has its own camera) - and not just that, the camera that the intersecting area belongs to, is disabled! - The problem was fixed by disabling that area, or just taking out its collider. However shouldn't it be enough just to have its camera disabled? - Thanks.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Button don't detect input if parent change position on-screen?
« Reply #4 on: August 19, 2013, 09:36:17 PM »
With the latest version, yes, disabling the camera should be enough.