Author Topic: OnSubmit sometimes calls the most recent button clicked. potential bug  (Read 5677 times)

zippo227

  • Jr. Member
  • **
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 55
    • View Profile
I have a button click that calls this function.

       
  1. public void InsertEmoji(string text)
  2.         {
  3.             Debug.Log("Inserted EMOJI");
  4.             //UIButton.current = null;
  5.             Insert(text);
  6.  
  7.             //Hack because the camera is not clearing this selection
  8.             UICamera.selectedObject = null;
  9.        
  10.             //Reselect the input
  11.             OnSelect(true);
  12.             UpdateLabel();
  13.         }

Sometimes after I click the button, I click the chat box and press enter to submit the text. This function gets called again for some odd reason. I just wanted to note this in case you might find a simple reason why it's happening. For now my fix is to manually set the UICamera.selectedObject to null as you can see in my code. That seems to fix the issue. Here is my stack trace.

Consortya.ChatInput:InsertEmoji(String) (at Assets\NGUI_Consortya\Scripts\ChatInput.cs:34)
Emoji:InsertSmile() (at Assets\NGUI_Consortya\Scripts\Emoji.cs:38)
EventDelegate:Execute() (at Assets\NGUI\Scripts\Internal\EventDelegate.cs:476)
EventDelegate:Execute(List`1) (at Assets\NGUI\Scripts\Internal\EventDelegate.cs:644)
UIButton:OnClick() (at Assets\NGUI\Scripts\Interaction\UIButton.cs:257)
UnityEngine.GameObject:SendMessage(String, Object, SendMessageOptions)
UICamera:Notify(GameObject, String, Object) (at Assets\NGUI\Scripts\UI\UICamera.cs:1079)
UICamera:ProcessTouch(Boolean, Boolean) (at Assets\NGUI\Scripts\UI\UICamera.cs:1851)
UICamera:ProcessOthers() (at Assets\NGUI\Scripts\UI\UICamera.cs:1602)
UICamera:Update() (at Assets\NGUI\Scripts\UI\UICamera.cs:1262)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: OnSubmit sometimes calls the most recent button clicked. potential bug
« Reply #1 on: February 05, 2015, 09:12:30 AM »
Camera won't clear the selection for you. Whatever you pressed on last will be what's selected.

zippo227

  • Jr. Member
  • **
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 55
    • View Profile
Re: OnSubmit sometimes calls the most recent button clicked. potential bug
« Reply #2 on: February 05, 2015, 11:38:12 AM »
Do you think though that when I submit to a text box, that the last button I pressed should not also be submitted?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: OnSubmit sometimes calls the most recent button clicked. potential bug
« Reply #3 on: February 05, 2015, 01:06:53 PM »
Not sure what you mean. Button get submitted?

zippo227

  • Jr. Member
  • **
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 55
    • View Profile
Re: OnSubmit sometimes calls the most recent button clicked. potential bug
« Reply #4 on: February 05, 2015, 01:13:44 PM »
The problem is this. I click a button, btnA. I then click into a UIInput, inptA and press enter to submit. The submit delegate associated with the inptA is called, and the camera also triggers a click on btnA. It should only call the delegates for inptA since btnA is in no way related to OnSubmit for inptA. However, this is not the case, and that is why I'm having to manually clear the current object (btnA) from the camera.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: OnSubmit sometimes calls the most recent button clicked. potential bug
« Reply #5 on: February 05, 2015, 01:17:36 PM »
There is no reason for it to call anything on the button after you've selected the input. UICamera.selectedObject will point to the input's game object.

zippo227

  • Jr. Member
  • **
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 55
    • View Profile
Re: OnSubmit sometimes calls the most recent button clicked. potential bug
« Reply #6 on: February 05, 2015, 01:19:54 PM »
agreed. maybe just take a look at the stack trace and you could notice a small bug. The Button OnClick is certainly being triggered without my clicking the button.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: OnSubmit sometimes calls the most recent button clicked. potential bug
« Reply #7 on: February 05, 2015, 01:27:30 PM »
Look closer at your own code attached to the button.

I did the following quick test:
1. New scene.
2. Dragged in a button and attached a script to it that Debug.Logs a message OnClick.
3. Dragged in an input field.
4. Play, click the button - see the log.
5. Click the input field, type something, hit Enter. No debug log coming from the button.

zippo227

  • Jr. Member
  • **
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 55
    • View Profile
Re: OnSubmit sometimes calls the most recent button clicked. potential bug
« Reply #8 on: February 05, 2015, 01:29:04 PM »
Thank you for looking! I'll see if I can make a similar test project when I get home tonight that does exhibit the issue. I will pm the project to you.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: OnSubmit sometimes calls the most recent button clicked. potential bug
« Reply #9 on: February 05, 2015, 01:30:05 PM »
Tried it with this script, same thing, works fine:
  1. using UnityEngine;
  2.  
  3. public class Test : MonoBehaviour
  4. {
  5.         public UIInput input;
  6.  
  7.         void OnClick ()
  8.         {
  9.                 Debug.Log("OnClick");
  10.                 input.value = "Testing";
  11.                 input.isSelected = true;
  12.         }
  13. }
  14.  

zippo227

  • Jr. Member
  • **
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 55
    • View Profile
Re: OnSubmit sometimes calls the most recent button clicked. potential bug
« Reply #10 on: February 06, 2015, 01:29:28 AM »
I also could not get the issue to happen in a small test project, but I don't want to have to send you my entire project. I believe the issue relates to line 1827 of UICamera, but I don't know how this line of code I suggest would affect mobile devices. This line is being called on key up from the keyboard, and I believe that means it should not be thinking about the whole dragged and touched things. Adding isMouse here fixes my issue, but it's something you should only add if you take a look and think it was a neglected line. Maybe a return was missing up above when the event was handled properly for the keyboard.

What if you made line 1827 of UICamera "if ((currentTouch.dragged == currentTouch.current && isMouse)  ||"   

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: OnSubmit sometimes calls the most recent button clicked. potential bug
« Reply #11 on: February 06, 2015, 09:46:45 PM »
Line 1827 for me is an empty line, so that doesn't tell me much. What version are you on?

zippo227

  • Jr. Member
  • **
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 55
    • View Profile
Re: OnSubmit sometimes calls the most recent button clicked. potential bug
« Reply #12 on: February 06, 2015, 09:48:33 PM »
I'm on 3.7.9