Author Topic: UIPopupList value always null  (Read 13547 times)

Bill.Smock

  • Newbie
  • *
  • Thank You
  • -Given: 6
  • -Receive: 2
  • Posts: 19
    • View Profile
UIPopupList value always null
« on: June 06, 2016, 05:50:49 PM »
I read through the class and it seems that anything that sets 'value' is now replaced because of UILabel > SetCurrentSelection.  Well, that means I need to use List.GetComponentInChildren<UILabel>().text to have the current selection.  Was this the intended setup? 

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIPopupList value always null
« Reply #1 on: June 06, 2016, 10:15:01 PM »
UIPopupList.current.value is only available during the popup list's OnChange callback. It's the only time the popup list actually exists in the world. If you need to save this value somewhere, simply catch the onChange event and save it somewhere.
  1. using UnityEngine;
  2.  
  3. public class KeepPopupValue : MonoBehaviour
  4. {
  5.     public string savedValue;
  6.  
  7.     void Start ()
  8.     {
  9.         var popup = GetComponent<UIPopupList>();
  10.         EventDelegate.Add(popup.onChange, delegate()
  11.         {
  12.             savedValue = popup.value;
  13.         });
  14.     }
  15. }

wizardsmoke

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 5
  • Posts: 40
    • View Profile
Re: UIPopupList value always null
« Reply #2 on: June 13, 2016, 09:20:10 AM »
I also encountered this issue.

UIPopupList.value used to be accessible any time.  This was consistent with the way that other scripts work, such as UIInput.

Also, setting UIPopupList.value used to only trigger callbacks if the value actually changed.  Again, consistent with UIInput.  It now triggers callbacks every time, unless the value is set to null.

I prefer the way that it used to work  :-\

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIPopupList value always null
« Reply #3 on: June 16, 2016, 03:29:28 AM »
Also, setting UIPopupList.value used to only trigger callbacks if the value actually changed.  Again, consistent with UIInput.  It now triggers callbacks every time, unless the value is set to null.
This was intentional. Popup lists for things like right-click menus would now allow for the same selection otherwise. For example right-clicking an item in Windward to bring up a popup list then choosing to link it in chat. First time would work, second time would not. Another example: right-clicking a player's name in chat and choosing to invite them to an instance. First time would work, second time would not. This was the reason for the change.

wizardsmoke

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 5
  • Posts: 40
    • View Profile
Re: UIPopupList value always null
« Reply #4 on: June 16, 2016, 10:55:01 AM »
This was intentional. Popup lists for things like right-click menus would now allow for the same selection otherwise. For example right-clicking an item in Windward to bring up a popup list then choosing to link it in chat. First time would work, second time would not. Another example: right-clicking a player's name in chat and choosing to invite them to an instance. First time would work, second time would not. This was the reason for the change.
That makes sense.  I think the issue here is that popup lists are being used in two very different ways:

1) Popup list as a context menu.  This is what you have described.  It does not exist while it is not being used by the user, so accessing its current value outside of the context of the onChange event does not make sense.  The value doesn't really change, it is just temporarily selected.

2) Popup list as an option (such as screen resolution or video quality).  This is how I am using it.  It always exists, even if the user is not currently using it, so I want to be able to see what its current value is.  The value does change, and it is important to know when if it has actually changed or if the user ended up choosing the same option.  The value can also be set programmatically (not by the user).

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIPopupList value always null
« Reply #5 on: June 18, 2016, 04:58:55 AM »
You can always save the value yourself as I've shown in the example above, then check for inequality inside.

Wumpee

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 53
    • View Profile
Re: UIPopupList value always null
« Reply #6 on: October 09, 2016, 09:54:05 PM »
Why would you use a UIPopup for a context menu... this has caused us some grief, and now we need to go and change all instances of popups to work differently.

It would have been nice to have this functionality as optional instead of forcing it.

Wumpee

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 53
    • View Profile
Re: UIPopupList value always null
« Reply #7 on: October 09, 2016, 10:24:06 PM »
The more I look at this, the more ridiculous I realise it is - Having to double handle data like this is sloppy.

Why not make a UIContextMenu object instead of destroying UIPopupList like this.

I'm going to attempt to revert to a prior version of UIPopupList for now.

I am a fan of your work, don't get me wrong, but this is just bad - you should always be able to access the current value of a popup list
« Last Edit: October 09, 2016, 10:35:12 PM by Wumpee »

arkon3

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 71
    • View Profile
Re: UIPopupList value always null
« Reply #8 on: January 28, 2023, 12:39:32 AM »
Hi, I'm currently stuck one this too. I have a uipopuplist but want to know the current selection, but as the popup hasn't been changed how do I get the initial value selected? No change event has occurred yet.