Author Topic: UICamera keeps on sending notifications to an object with a disabled collider  (Read 4583 times)

Game Whiz

  • Guest
Hi,

In my game I have a direction wheel that gets OnPress/OnDrag notifs from UICamera. Everything works as expected. Now I'm implementing some cinematic scenes, i.e. when the player reached a checkpoint, he's no longer in control and a script is run to control NPCs and the player. So that the player doesn't interfere with the scripted movement, I have to disable the direction wheel, and I'm finding some issues here.

For example, if while I'm pressing the direction wheel, I deactivate the direction wheel's collider, after deactivating the collider I still get OnDrag messages from UICamera. This is AFTER the collider was disabled:

DragSpin:OnDrag() (at Assets/scripts/Components/GUI/DragSpin.cs:88)
UnityEngine.GameObject:SendMessage(String, Object, SendMessageOptions)
UICamera:Notify(GameObject, String, Object) (at Assets/NGUI/Scripts/UI/UICamera.cs:546)
UICamera:ProcessTouch(Boolean, Boolean) (at Assets/NGUI/Scripts/UI/UICamera.cs:965)
UICamera:ProcessMouse() (at Assets/NGUI/Scripts/UI/UICamera.cs:796)
UICamera:Update() (at Assets/NGUI/Scripts/UI/UICamera.cs:654)


Is there any other way to deactivate a particular widget while showing it on screen, other than deactivating its collider?

Best regards,
Alex

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Why don't you deactivate the UICamera itself during cut-scenes?

Game Whiz

  • Guest
Because it's not a good solution in my case. These cut scenes resort to in game graphics and NPCs, not an external video.

I want some of the UI to be working (e.g. pause button) and I want all of the UI to remain on screen, to allow the player to quickly resume playing when needed (this is for iOS and controls are on screen).

For instance, I have cut scenes where the player gets surrounded by enemies, there's a small amount of dialog and when the cut scene ends the player is immediately back in play. Making the UI pop out and in would be both confusing and inelegant. Not having a pause or skip buttons during cutscenes isn't even an option. I hate games that impose stuff on you.

If there's no elegant way to solve this, I could not react to input in a given state, but that just seems wrong when I have this beautiful UI system in place ;)

Is there any circumstance where you'd want the widgets to continue responding after their collider has been disabled?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Judging by what you are trying to do, I am guessing your issue comes from the fact that you are deactivating a collider of a game object that already started the press event. Is that the case? If so, you need to manually cancel this event by setting UICamera.currentTouch.pressed = null.

Game Whiz

  • Guest
Yes, that's the case. Setting UICamera.currentTouch.pressed to null doesn't work, because UICamera.currentTouch is null when I'm trying to deactivate the control (I'm testing in the editor, with the mouse. Didn't test on the device.).

Even if I set currentTouch to null, new touches are being generated if I drag around.

So that it's clear, the current flow is:

1- Press and drag direction wheel
2- Player moves
3- Player crosses checkpoint while direction wheel still being touched (but no events are being generated since the finger/mouse pointer is standing still)
4- I deactivate the direction wheel's collider
5- I still get OnDrag notifs if I drag around

If I end the drag (i.e. stop pressing the mouse button) and try to click again, then it works as expected (no input is detected).

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
You need to deactivate it inside an event call back such as OnDrag. Otherwise there is no "current" as there can be multiple touch sources.

Game Whiz

  • Guest
Ok, of course. It was just after lunch and I was half asleep :) I'm storing the last touch of a given control and cancelling it when I deactivate the collider. It's working now. Thanks!