This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
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:
https://postimg.cc/CRRrf4fR

I select my nodes:
https://postimg.cc/S2gcrwBk

Next I instance my player scene in the MainScene
https://postimg.cc/jWKNrxKR

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()
Character2D.gd:22 @ _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.