Hey there, my radiogroup looks like this initially when I run the game:

But clicking one of the other options changes the styling to this:

I don’t see a way to change the styling of this in the UI Builder. So, how can I do this manually in the uss file?
Also, why does the title style change when something is selected?
Hello! This is happening because the radio button and the radio button group are showing as selected, with the pseudo state “Focus” to be more precise. You can read about them in the documentation.
You’ll need to override the style defined by the Default Runtime Theme, you can do that by declaring something like this on your USS (this will make the font purple instead):
.unity-base-field:focus > .unity-base-field__label {
color: purple;
}
You can, in theory, prevent the focus color change by using this line, but for accessibility and usability reasons it’s preferred that focus/selection does a color change:
.unity-base-field:focus > .unity-base-field__label {
color: initial;
}
Thanks, I’ll give that a try.
I finally got around to wiring things up and I can’t figure out how to get which item is selected. I thought it would be the radio button group’s value field, but that’s always 0. I tried using RegisterValueChangedCallback on the radio group and each of the items. It only fired for the radio buttons, not the group. But I don’t see anything in the ChangeEvent that tells me what the source of the event was.
Can you point me to a working example of using the radio button group?
I’m having a hard time finding an example now, I can keep digging but first can you confirm that you’re not adding individual Radio Buttons under the Radio Button Group, but actually using the “Choices” field in Radio Button Group? It’s designed to work with the “Choices” field.
That was it! I deleted the ones I manually added and used the Choices field and the group button value changed event fired and value was what I expected.
Thanks for your help!
1 Like