The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

I'm trying out scriptable objects in Godot and I ran into an issue with an export variable that is of type NodePath.

My object

  export (NodePath) var rayCast
  export (NodePath) var animatedSprite

  onready var ray = $rayCast
  onready var anim = $animatedSprite

In the editor
I create my player scene with my scriptable object as the root node:

I select my nodes:

Next I instance my player scene in the MainScene

But when I press run:
I get the error :

E 0:00:00.498 get_node: Node not found: animatedSprite.
<C++ Error> Condition "!node" is true. Returned: __null
<C++ Source> scene/main/node.cpp:1381 @ get_node() @ _ready()

Do I get this error because my animatedSprite NodePath no longer finds the node?

Godot version 3.2.3.stable
in Engine by (17 points)

please show your _ready method

1 Answer

+1 vote
Best answer

When a node is initialized it's global variables are set first. In the example you provided since $rayCast and $animatedSprite are not part of the sceneTree this error is thrown when you try to get their nodes.

When referencing a node using get_node which is what $ does, the referenced name must be exactly as seen in the sceneTree like this

onready var ray = $RayCast2D
onready var anim = $PlayerSprite

And if it's not yet part of the sceneTree use var instead of onready var

by (6,942 points)
selected by
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.