How do I convert "export(NodePath) onready var node = get_node(node)" in Godot 4.0 R6?

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

I was following this tutorial:

However, I ran into a syntax issue with how they were assigning a node path through the editor and immediately reassigning the variable as the node.

I split it into two lines like this:
@export var node_path : NodePath
@onready var node = get_node(node_path)

This became a problem later on when I instantiated the scene. The children of the scene root are instantiated, but don’t have parent/child connections. _init() runs, but get_parent() will return Null. So trying to assign it in the _init() didn’t work.

The implementation used in the tutorial doesn’t rely on adding the scene to the tree prior to assigning variables and running functions. So _ready() isn’t reached right away.

When I tried “@export @onready var node = get_node(node)” I got a cyclical error even with the export assigned a node path in the editor.

I’m hoping there’s a way to recreated what they did in the tutorial with updated syntax. Any help is much appreciated. I’d rather not have to completely rewrite the implementation.

:bust_in_silhouette: Reply From: TremblingInferno

I think simply

@export var node : Node

should work. It did in 4.0 beta 13