#How do I export nodes?
1 messages · Page 1 of 1 (latest)
Hello! Yes I can! I hope these help!
The beat variable is a child timer to the metronome, and current_bpm is an enum that's preset in the script.
**The error I get is: **
Invalid assignment of property or key 'wait_time' with value of type 'float' on a base object of type 'Nil'.
This is the function it happens at:
func set_pace(new_bpm: BPM) -> void: current_bpm = new_bpm # TODO: Change back to 60. The divison is by seconds. beat.wait_time = 30.0 / float(current_bpm)
Hello again!
In short
set_pace() is called during _init() but it relies on a node assignment @onready var beat = $Beat which happens later, during the ready phase. And so the node Beat cannot be found. (It hasn't been loaded yet)
Explanation
"On a base object of type nil"
This is telling us that we dida.band A somehow doesn't exist. (A is the base object) So when we didbeat.wait_time,beatsomehow doesn't exist (it's nil/null)
It's probably happening because you're trying to use $Beat (get_node()) before the needed nodes have been added into the tree (before they are ready).
_init() runs before _ready(), and before any of the node's children have been added. It also runs before any @onready variable assignments.
Why does _init() run before children have been added?
This is related to the order in which Godot loads the nodes inside a scene / nodes with children, and the order in which it activates the callback functions of each involved node like _init(), _ready(), and _process()
It begins with the root node, calling its _init(). Then it loads any children, in order, calling their _init() recursively (so deeper children as well) Working downward.
Then it works back upward calling _ready() and doing @onready assignments on deep children first, then their parents. A node's _ready() is run after all of its descendants' _ready()s have run.
More reading on that
https://kidscancode.org/godot_recipes/4.x/basics/tree_ready_order/index.html
https://docs.godotengine.org/en/stable/tutorials/scripting/scene_tree.html
Solutions
Make your own init function, named init() without the _ perhaps. Call it in _ready(). So that set_pace() which uses $Beat can properly get the node.
Or just put your _init() code in _ready() instead / rename init to ready