Author Topic: UIButton Hovering  (Read 6536 times)

harshman_chris

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
UIButton Hovering
« on: May 16, 2014, 11:15:43 AM »
I have 3D objects that when clicked on they open a Menu of UIButtons, these buttons have tooltips. The problem is that the UIButton does not trigger that the mouse is over the UIButton when the button is enabled when it is under the mouse at time of being enabled.

I am looking for a way to force a check to see if the mouse is over the UIButton.


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIButton Hovering
« Reply #1 on: May 16, 2014, 02:49:49 PM »
Why not? The UICamera performs raycasts periodically in its Update function -- ever 20 ms. Line 1080 of UICamera.cs. You can test this by adding a button to the screen and putting a tween on it, making it tween from one side of the screen to another slowly. Leave your mouse cursor in its path, and you will see it highlight when the mouse moves under it.

harshman_chris

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: UIButton Hovering
« Reply #2 on: May 16, 2014, 03:29:38 PM »
I think it is because the button gets disabled when I turn off the sprite, and then when I turn it back on it gets enabled. I am not sure, and as far as I know it should actually pick up if using a ray trace. I just know it is not, until I move the mouse on and off the button. Clicking the button still works, but it will not show the hover or trigger tooltips.

I have turned off ray casting hitting triggers, a requirement because I use large trigger area's for finding enemies. I changed the colliders that are created on the UI elements to not be triggers but that shouldn't change anything like this since the UICamera works off raycasting. I have tested them as triggers with the same result as well.

With the tween example the mouse may not move but the button is moving, with this neither is moving, I am not sure why that makes a difference.

I have spent some time going through the camera code and as far as I can tell it should actually work, why it is not I am unsure at this time.
« Last Edit: May 16, 2014, 10:32:49 PM by harshman_chris »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIButton Hovering
« Reply #3 on: May 17, 2014, 04:43:46 PM »
"that shouldn't change anything" are famous last words in software development. Using larger colliders for certain things isn't a good reason to disable raycast hitting triggers. When you do a raycast you perform it into a specific layer or a group of layers. You choose which layers are hit and which ones are ignored. This is specified on the UICamera.

harshman_chris

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: UIButton Hovering
« Reply #4 on: May 17, 2014, 08:29:05 PM »
That may be the case and it normally is, but  I have tested both methods as I mentioned and it did not change anything.

As for the large collider it is used to detect enemies with a range, and cache them rather than doing a search for enemies every .xxx seconds. Unfortunately both colliders are on the same object.
« Last Edit: May 17, 2014, 08:43:45 PM by harshman_chris »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIButton Hovering
« Reply #5 on: May 18, 2014, 10:47:29 AM »
You have two colliders on the same object? That's... wrong. You need to have colliders on different objects, each object on their own layer. Simply parent them to the same common object instead.

harshman_chris

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: UIButton Hovering
« Reply #6 on: May 18, 2014, 11:56:02 AM »
It might not be the best practice, I re-factored the code and second collider to make it better, did not however fix the problem.