The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

0 votes

Sometimes i get the error :

"Attempt to call function createtimer in base null instance on null instance"
And it comes from yield(get
tree().create_timer(0.2),"timeout")

What are the situations when get_tree() returns null ? Error happens in the middle of game, everything is ready for a long time, this code is not in Autoload... I use yield with dynamic timers everywhere in my code and it generally works

Godot version godot 3.2 stable
in Engine by (8,188 points)

1 Answer

+2 votes
Best answer

get_tree() will return null if whatever is calling it is not in the SceneTree. This can be fixed by simply adding the node to the SceneTree, then having the node call get_tree() wherever it needs to.

by (347 points)
selected by

I see. Node calling yield responsible for this error actually was in scene tree, but could it mean that it queued itself free or was deparented while this 0.2 timer was going ? My code might have let such situation happen

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.