What happened to UiRadioButtonCommunicationBus?

Hey

I’m trying to add options to the dropdown using UiSpawner dynamically. With how slices work, I need to add the element Owning Dropdown on the DropdownOption component and the group to the RadioButton component through a Lua script. I managed to get the Owning Dropdown on the DropdownOption component working. What I need now is to set the group on the radioButton component.

Using this specfic Lua reference:

UiRadioButtonComponent - Lumberyard User Guide

I found the UiRadioButtonCommunicationBus, which says I can change the group through SetGroup. In the Lua editor, it does not seem to exist or able to be accessed.

Is there an alternative method I can use?

Hi @Tarn1902,
So this is a bit outside my area of expertise but I did reach out to an expert and we chatted about this issue. Let me relay the information that was given and you can let me know if it works.

  • Looks like SetGroup is on // UiRadioButtonCommunicationInterface
  • where as GetGroup is on // UiRadioButtonInterface
  • But UiRadioButtonComponent does inherit from both of those busses
  • It feels more like you’re not intended to call SetGroup
  • Instead you’re expected to do something like this

UiRadioButtonGroupBus.Event.AddRadioButton(group_entityid, button_entityid)

  • So it sounds more like the answer is, a radio button group is an actual component, on an entity, with an entityid.
  • So after spawning your radio button you’d call

UiRadioButtonGroupBus.Event.AddRadioButton(entityid_of_the_enity_with_the_radiobuttongroup_component, entityid_of_the_radiobutton)

  • This internally calls SetGroup and adds it to the list
  • We have an actual example of what this person is doing in fact.

Gems/LyShineExamples/Assets/UI/Scripts/LyShineExamples/Spawner/RadioButtonSpawner.lua

function RadioButtonSpawner:OnTopLevelEntitiesSpawned(ticket, ids)
    -- we could do this in OnSpawnEnd but this is a convenient way to add each top-level element
    -- spawned to be part of the radio button group. There is only one top-level element in the
    -- dynamic slice and we know it is the radio button
    for i = 1,#ids do
        local parent = UiElementBus.Event.GetParent(ids[i])
        if parent == self.Properties.SpawnerElement then
            UiRadioButtonGroupBus.Event.AddRadioButton(self.Properties.SpawnerElement, ids[i])
        end
    end
end
  • Note that AddRadioButton automatically calls SetGroup but also adds the button to the list of buttons that the group manages
  • But it looks like in lyshine there is an entity (with an id) that has a RadioButtonGroup component on it.
  • That component’s job is to keep a list of all the radio buttons in the group so that when you click on one it can loop over the rest and turn them off
  • Once you spawn a radio button (which is the individual clickable thing) you need to add it to the group that handles it, so that it can start tracking it
  • They should not list SetGroup, that is private
    *They should instead say in GetGroup that you can use the Radio button group Bus event “AddRadioButton” to change groups, see (blah blah example).

Hope this helps,

3 Likes