Getting text string from dropdown options

Hey guys,

I’m working in unity 2021.3.9f1 and want to grab the text value from a TMP dropdown list, and pass it into a string variable.

I want to do that so I can allow users to set their own dropdown list items. I also use the list items to set section headings in a panel. (Plus my functioning graph isn’t exactly streamlined.)

I’ve found a c# code snippet, but I can’t find the right nodes to convert it to visual scripting. I"m avoiding c# as much as possible.

the code is: Debug.Log(Dropdown.options[Dropdown.value].text);

I’ve tried a variety of nodes, as you’ll see from the screenshots. (Pic one is all the nodes - pic 2 is zoomed in to show detail.) The transform node I’m using is to try and grab the string from the dropdown label child object.

Can anyone point me in the right direction?

Thanks heaps for the help,
Canley

TMP_Dropdown
Get Caption Text —> TMP_Text Get Text
outputs the string lol

but looks like you’re getting a null component

Thanks that looks great, and the null might be because I was trying to get it from the dropdown label rather than the parent.

I can’t find the TMP_Text nodes though. Guessing I’ll need to add them in preferences, but no luck trying things as yet.

Any idea what I need to add? Is it a type option?

Thanks heaps :slight_smile:

Make sure you have the TMP assembly in the Visual Scripting Project Settings window

not a type but the assembly

Thanks Redact.

I had Unity.TextMeshPro already, but not .Editor.

So I’ve added that, regenerated, restarted the project, but still no “tmp_text” nodes.

Gonna try in an empty project and see if that helps.

no joy with that attempt :frowning:

just type “TMP get text” into the fuzzy finder.
drag every single get text you see onto the graph and try to match up the icons

the new TMP is not the same as old TMP
bunch of versions that all spamm it up

you can try to add tmp text as a type and regenerate too

do you have the TMP dropdown?

Great thanks I’ll try all that. I’ve got the TMP dropdown.

It’s working!

Thanks for the guidance I really appreciate it :slight_smile:

So this might not be the best solution, but what I’ve done is add a tag to the label child object of the dropdown, find that object, and use text mesh pro ugui to pull the text from it.

One error in what I’d tried with earlier exploring was to look for text mesh pro nodes rather than text mesh pro ugui.

Just trying to match up the icons helped a lot.

Cheers,
Canley

1 Like

You’ll quickly run into performance issues with Find methods in OnUpdate. Any kind of Find is slow already, performing that every frame quickly compounds the issue. It would be better to cache the object you’re looking for in an Object variable manually, or use Find in OnEnable or OnStart.

Finding the object by loose string names also keeps your project architecture fragile - if you rename the object later or remove it completely, the logic breaks. Variable use would aid in keeping the project manageable long term.

1 Like

Thank you PanthenEye - I’ll integrate that. I probs use OnUpdate way too much.

WooT

If it wasn’t for the fuzzy finder and expose nodes i’d have never found it lol

look at the size of this expose node! rofl

Crazy!

I’ll have to try fix my tmp_text problem somehow - lots of nodes seem to output it.

Ok well I still haven’t been able to add TMP_Text nodes, but I added Text Mesh Pro UGUI as a type in settings, then was able to pull a string directly from the dropdown caption text as in the pic:

That’s simple and doesn’t require either finding the label child object or giving it a variable.

Thanks again for the help :slight_smile:

1 Like