Get_text() function on Textedit Node returns <null>

Godot Version

Godot 4.0.4 stable


I am trying to save the text value of a textedit node to a string variable with the get_text() function. This is where the weirdness starts, in a global function called by another script this function returns null, but in an _process() loop on one frame it returns the correct text and the other null again. Here is the code for the textedit node:

extends TextEdit

func _save():
	var check2 = get_text()
	print("name" + check2)
	text = ""
func _process(delta):

Ignore the text = "" line i doubt that’s the problem
Please note I am new to Godot (I’ve been using it on and off for like 2 months) the solution may be obvious to you, but anyways thanks for your help!

Tested your code and don’ get any nil value.
The problem seem to be somewhere else in your project.

1 Like

You are right, no idea what’s happening in my current project

it could be just your global function/script calls _save() before this text edit node is ready (also known as it’s instantiated in a scene tree).
try add await function like

await get_tree().physics_frame()

before the var check2= get_text()

I’m getting this error:

Parser Error: Name "physics_frame" called as a function but is a "Signal".

but i don’t think that’s the problem, even in a clear scene with only the textedit on the tree it still does its weird stuff

sorry forgot to remove the ()

await get_tree().physics_frame