Having access to a variable (which is line_edit.text)

Hi,
So I am trying to do a name selector that if you write a certain name it changes the sprite.
But I don’t know how to have access of the variable of the name because the naming process is in another scene. And even if I try to put it in the same scene it gives me:

Invalid access to property or key’text’ on a base object of type ‘null instance’
The variable is the line_edit.text because I want the variable to be the input of the name.


(the name selector)


here is where i am trying to put the variable line_edit.text
If it’s not clear i am so sorry…

Where you’re assigning the node for the line_edit variable? Will helps if you show the entire code.

Also you can try: Name = %LineEdit.text

1 Like

Thank you ! I tried to do it but it still gives me the same error since i think it is because it isnt
I am assigning the variable in a node 2d and not a line_edit.
And i am assigning the line_edit variable in a 2d node

From the pic you added i can see why this not works, because unique node names has the same scene limitation, so you can’t get your node like you’re doing now.

You can try use get_parent().get_parent().get_node("LineEdit") for get your line edit or add the line edit node to a group from the editor, select the node and do this:

And use get_tree().get_first_node_in_group("group_name") to get your node from code.

1 Like

thank you but- I don’t see for what i need to use that i am so so sorry. I have tried to do that :


But it still gives me the same error message- I am so sorry to bother you and thank you again !

I tried to print without the text to understand a bit more
image

When i start the scene it prints
image
But as soon as a i enter the name it prints :
image

If works at the start but fails later that means the line edit is being deleted from the scene

1 Like