Can't take Local Variable from ObjectReference

When i write something like:
{gameObject.myName} or {NameTest.myName}
then
FormattingException: Error parsing format string: Could not evaluate the selector “gameObject” at 13
My name is {gameObject.myName}

How can I get the variable myName?

8459984--1123166--Screenshot_3.png 8459984--1123169--Screenshot_1.png

Did you drag in the script? You need to drag a reference to the component. Make sure its the component and not the GameObject.

1 Like

I drag this script, it seems like component.
Or I wrong?

Can you try doing {myName.GetType}
If it doesn say NameTest then you dragged in the wrong object.

1 Like

It say NameTest

oh I see the problem.
You need to do {myName.myName}
The 1st call gets the object reference and the 2nd will extract the field value.
You probably want to rename the local variable to something else so its less confusing.

2 Likes

Thank you very much!
I’m just still learning

1 Like