get_node("Sprite").visible = false, not working, ik its an embarassing question...

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

Node (parent) (where script is located) <------------ Scene
Sprite (child) (being affected by the script)

Code:

extends Node

func _ready():
$Sprite.visible = false

Error:
Invalid set index ‘visible’ (on base: ‘null instance’) with value of type ‘bool’.

PS: Im new to Godot…

Thanks In Advance

Scenetree:

Node (called scene)
Sprite (called Sprite)

Code:
extends node

func _ready():
$Sprite.visible = false

whenever i run it the error (shown above) occurs
visible is a property belonging to the Sprite

SirSqueakers | 2020-06-11 11:16

also in the error tab it shows this:
get_node: Node not found: Sprite

… Im utterly confused

SirSqueakers | 2020-06-11 11:19

extends node

func _ready():
$Sprite.visible = false

idk how to make a screenshot so this is it, literally, there’s nothing else, just this code

scene (on the right of it is script)
Sprite (on the right of it is toggle visibility)

Sprite already exists there is no code instancing it, or anything, its all manual except the code above, telling the Sprite what to do when func ready is called the script gets the node Sprite, then it changes its visibility to false, i think its something “with scene” node cus, when i put the script in the “Sprite” node and do self.visible = false, it works and i cannot see it, is my project cursed or is my path being read wrong, because it also shows that i cannot find node “Sprite” even though its there!!! wth godot!?

SirSqueakers | 2020-06-12 11:20

:bust_in_silhouette: Reply From: whiteshampoo

Looks like your parent has no Node with the name Sprite.
Are you sure you have named it like that?
$[name] is not the Nodetyp, but the actual name in the tree!

null instance means, that there is no instance. An nothing can’t have a variable called visible

You can also try putting onready to ensure that the variable is called/assigned when the child is already instantiated

nightrobin | 2020-06-11 09:04

Node is the parent of the Sprite, node has the script in it. Then I put the script in sprite, and did self.visible and it worked
the Sprite’s name is Sprite so it should be working
in the properties tab of Sprite (which exists) has an option called visible and i can toggle it.

I just want to access a node’s ability to toggle visible.
Sorry for the wait

SirSqueakers | 2020-06-11 10:58

This should work.
Can you provide your project, or make screenshots?

whiteshampoo | 2020-06-11 11:22