How to export variables in godot 4.0?

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

I got a Godot 4.0 unstable build off of today. I found that some keywords don’t work. Mainly, what do you do in the place of export, and onready?

:bust_in_silhouette: Reply From: duane

@export and @onready. It would be nice if the documentation for 4.0 was finished.

How do you use it? To export a Node3D variable, what do you do?
I tried this:
@export(Node3D) var follow, but It didn’t work

Nv7-GitHub | 2020-10-06 00:38

I also tried doing @export var follow: Node3D, @export var follow: Node3D =, @export var follow: Node3D = null, and @export var follow =

Nv7-GitHub | 2020-10-06 00:41

Unfortunately, there are still a lot of bugs:

duane | 2020-10-06 02:28

The documentation is being updated here:

See also GDScript progress report: New GDScript is now merged

Calinou | 2020-10-06 20:40

:bust_in_silhouette: Reply From: codevanya

For normal variables:

@export var health : int

NodePath export has been changed to this:

@export_node_path(Resource) var resource_name

Thanks! This is what I was searching for. Where did you get the information about @export_node_path if you don’t mind me asking?

Hammo | 2022-08-15 15:40

sadly you can’t add :Array to an @export_node_path

@export_node_path(Marker2D) var waypoints: Array

*this wouldnt work…

But you can do in fact.

@export var waypoints: Array

Then you get a NIL Entry, you can change the size of the array and with a click on the PEN, you can define what kind of Node it should be… There you can select node_path and select your desired nodes. But doesnt work anymore in one script line…

Took me ages to figure it out as there is still no documentation for this.

MikeSter | 2022-09-24 16:13

1 Like
:bust_in_silhouette: Reply From: salihkallai

Since Godot 4.0, nodes can be directly exported as properties in a script without having to use NodePaths

# Allows any node.
@export var node: Node

# Allows any node that inherits from BaseButton.
# Custom classes declared with `class_name` can also be used.
@export var some_button: BaseButton