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?

asked Jan 29 in Engine by Martik (17 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 : )

answered Jan 30 by Merlin1846 (172 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.