If statements under _ready function

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Martik

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?

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: GDScript basics — Godot Engine (3.2) documentation in English

Bernard Cloutier | 2020-01-29 16:36

:bust_in_silhouette: Reply From: Merlin1846

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 : )

Thanks it did worked!

Martik | 2020-02-05 16:56