Node not found?

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

There is a part in the player’s code where I had to use get node on the player’s sprite. So I wrote it like $Sprite, the sprite node itself is just called Sprite and it worked previously. But now it comes up with an error and says it can’t find it. The sprite node is also a child of the player node.

I’m quite new to Godot and coding in general so I’m not sure if I’m missing something?

Can show post picture of your scene tree.

supper_raptor | 2020-04-05 17:46

Node not found happens if the node from which you use get_node does not have Sprite as immediate child. Maybe you moved it one level deeper?

Zylann | 2020-04-05 21:56

No, it’s its immediate child I even double checked just to make sure :confused:

CyanGhosty | 2020-04-06 11:26

Can you post your code?

Zylann | 2020-04-06 11:34

	
else: 
	motion.x = 0
	motion.y = 0
	$Sprite.stop()
	$Sprite.set_frame(0)

CyanGhosty | 2020-04-06 11:39

Whole code? Or your project, if you can

Zylann | 2020-04-06 12:48

extends KinematicBody2D

var motion = Vector2()
export var speed = 100

func _physics_process(delta):
if Input. is_action_pressed(‘ui_right’):
motion.x = speed
$Sprite.play(“right”)
if Input. is_action_pressed(“ui_run”):
motion.x = speed*2

elif Input. is_action_pressed('ui_left'):
	motion.x = -speed
	$Sprite.play("left")
	if Input. is_action_pressed("ui_run"):
		motion.x = -speed*2
	
elif Input. is_action_pressed('ui_down'):
	motion.y = speed
	$Sprite.play("down")
	if Input. is_action_pressed("ui_run"):
		motion.y = speed*2
	
elif Input. is_action_pressed('ui_up'):
	motion.y = -speed
	$Sprite.play("up")
	if Input. is_action_pressed("ui_run"):
		motion.y = -speed*2
	
else: 
	motion.x = 0
	motion.y = 0
	$Sprite.stop()
	$Sprite.set_frame(0)
move_and_slide(motion)

Does that help?

CyanGhosty | 2020-04-06 12:54

Not really… at this point I’m still pretty sure your Sprite has been moved or has a typo in its name. I’d need to see the project.
Also judging by $Sprite.play("down"), it looks like your Sprite is actually an AnimatedSprite (but only the name should matter)

Zylann | 2020-04-06 14:02

So how would I go about sharing the project with you? As I said I’m new to this

CyanGhosty | 2020-04-06 14:46

You can use file transfer: https://send.firefox.com/
Or Google Drive, or Github
Even though I believe your problem is probably something really simple

Zylann | 2020-04-06 14:48

Loop – Google Drive
Like that?

CyanGhosty | 2020-04-06 14:57

I tried opening it but all scripts are empty and Room.tscn does not open. Looks like it’s not the whole project.
Wait…
You put scripts and assets in the .import folder? I strongly suggest you don’t do this xD .import is reserved for cached import files. Godot has a problem loading Room.tscn for another reason, but because it is in .import, I can’t fix it because the file explorer does not let me access it in the editor.

Zylann | 2020-04-06 17:10

:bust_in_silhouette: Reply From: Zylann

After having a look at your project, I saw what’s going on:

You are getting an error about Sprite not being found because when the game runs, you have two player scripts.
One is inside the room, and does have a child Sprite, which is ok.
However you also have an autoload called Player with another instance of the Player.gd script on it. That node does not have a Sprite child, and that’s where the error occurs. I suggest you remove this autoload because it’s a duplicate of what you have in the scene already, and you are not using it anywhere.

Another important thing: you placed assets inside the .import/ folder. You should not do this. .import is reserved for cached import files, and is a folder that can normally be deleted safely and not included to version control (because it’s all “temporary” cache files, really).
The save dialog allowed you to save files to it, but this is not really intented, probably should be raised as a bug.
Side effects of this are:

  • Assets in that folder cannot be accessed from the File Explorer. The scene magically loads when the project opens because it’s the main one, but if you close it you can’t reopen it again.
  • Searching in files from the script editor does not include this folder, because again, it’s not supposed to contain your assets.
  • Quick-open also doesn’t list these assets (Ctrl+Shift+O and Ctrl+Alt+O) for the same reason
  • Maybe more

Thank you :slight_smile:

CyanGhosty | 2020-04-06 17:34

hello im sina my project is grand theft auto iv physic version driving game i added ths spcrite

extends Node

var a = 0.0
var t = 0.01
func _ready():
$Engine.play(0.01)
set_process(true)
func _process(delta):
if Input.is_key_pressed(KEY_SPACE):
$spo.value = 1000
else:
$spo.value = 0
$Tween.interpolate_property($HSlider2, “value”,
$HSlider2.value, $HSlider.value, 0.1, Tween.TRANS_CUBIC, Tween.EASE_IN_OUT)
$Tween.start()
if t < 0:
t = rand_range(0.005, 0.02)
a = rand_range(0.1, 0.2)
$Engine_Ramp.seek(($HSlider2.value/1100)+a)
else:
t-=delta

info
spo means car engine sound hslider
and engine is audiostramplayer 3d i used truck town project for this
please help error is

E 0:00:14.769 get_node: Node not found: spo.
<C++ Error> Condition “!node” is true. Returned: __null
<C++ Source> scene/main/node.cpp:1381 @ get_node()
carsound.gd:11 @ _process()

help me plz plz!!!

and info gta iv car driving game comming soon if this problem solves new car game from godot think it my discord name is sina#3594
plz invite me to ur channel plz

sinaspogames | 2020-07-07 17:38