0 votes

Any If statement under ready function doesn't seem to work. And I don't want to use process(delta). How can I make nodes do something ONCE when a condition changes?

in Engine by (32 points)

Please post your code.

How can I make nodes do something ONCE when a condition changes?

Do you want to react to a change? The _ready function is called once when the node enters the tree. It won't be called again after that.

The best way to react to something without checking a condition every frame in _process is to use signals: https://docs.godotengine.org/en/3.2/getting_started/scripting/gdscript/gdscript_basics.html#signals

1 Answer

+1 vote

I've had that problem too but I found a way around it. During the first frame Godot sets things up and you see the Godot logo, so what you do is put this after ready then the rest of your code. So this.

var example = null

func _ready():
   if example == null:
         example = "example"

would be this

var example = null

func _ready():
   yield(get_tree(),"idle_frame")
   if example == null:
         example = "example"

I noticed that only sometimes I have to do this other times I don't it's odd.
But anyways hope this works : )

by (557 points)

Thanks it did worked!

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 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 webmaster@godotengine.org with your username.