How to change text style of TMP in script?

I would like to change the text style(which is defined in the style sheet) of the TMP component in code.
It seems that there is no method for changing text style during runtime.

Changing the name of textStyle was not working. It changes only the name of the text style.

tmp_text.textStyle.name = "H1";

How can I change TMP_Style of TMP_Text in script?

Short Answer: Currently no. No easy way to do it.

Long Answer: But you can do it in a hacky way.

You can get the OpeningTags to a StyleTag by calling the following function: TMP_StyleSheet.GetStyle("[StyleName]").styleOpeningDefinition (with TMP_StyleSheet being a reference to the used TMP-StyleSheet).

So a possible solution is to extract the StyleName from your string (e.g. "(...text) <style=Example> (text...)" would become ("Example") and feed it to the function above. Regular Expressions can help to extract the StyleName from your string. Then replace the whole tag with whatever the function returns (e.g. "<size=125%>"). (Note: It returns Null if the tag does not exist). Then do the same with the closing tag.

I don’t know if it’s answered your question. Or maybe I’m miss understood your question.

tmp_text.textStyle = TMP_Settings.defaultStyleSheet.GetStyle("[StyleName]");

It works for me

I copied and pasted your exact question into google:

1st result:

more:

https://forum.unity.com/threads/textmesh-pro-change-bold-underline-at-runtime.515623/

google is your friend. unity has all their documentation online.