0 votes

New to programming so I followed a tutorial a while back on Godot 3.X and after downloading and upgrading the project to beta. Exporting NodePaths changed and gives errors when trying to use them the same way. in 3.X it looked like this:

export(NodePath) onready var some_node 

and after assigning a node to the variable in the instector. I could use the shorthand variable and . to change properties and whatever. But in 4, it looks like this:

@export_node_path(Node2D) @onready var some_node 

But whenever I try to use the variable in any way, Godot gives me errors like this:

Cannot find property "modulate" on base "NodePath".

I've looked at the docs and tried to find information but can't find straight answers.

Godot version 4beta12
in Engine by (24 points)

To follow up, if you export a NodePath, you have to use get_node() on that path to actually reference the node. This was true in 3.x and is still true in 4.

1 Answer

+1 vote
Best answer

In Godot4 you can export a complete node instead.

So you can use

@export var some_node: Node2D

and then not only can you choose the node with an easy to use popup window but use the node directly as well without any @onready and so on.
I hope this part of the docs will help you with this: https://docs.godotengine.org/en/latest/tutorials/scripting/gdscript/gdscript_exports.html#nodes

Good luck with your project!

by (189 points)
selected by

That's exactly what I needed. Thank you so much!

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 Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.