Godot Version
Question
I have the following line in the _process function of CharacterBody2D: $Control/TextureButton.hide()
When run, this line returns Attempt to call function 'hide' in base 'null instance on a null instance.
How do I fix it?
I have the following line in the _process function of CharacterBody2D: $Control/TextureButton.hide()
When run, this line returns Attempt to call function 'hide' in base 'null instance on a null instance.
How do I fix it?
That means, that you do you do not reference an existing Node in your scene tree.
Based on $Control/TextureButton.hide()
you try to access a node in the following scene tree:
The error message means, that in your scene tree
CharacterBody2D
with a name of Control
orControl
with a name of TextureButton
Do your nodes have different names?
The path looks like this:
>Parent Node (node)
>>CharacterBody2D
>>Control
>>>Textutebutton
So Control
is a sibling of CharacterBody2D
.
Something like this should work, because you need to access the sibling via the parent node: $"../Control/TextureButton".hide()
But I wouldn’t suggest to use this usage pattern, because traversing the scene tree over parent nodes easily breaks when you change your setup of the scene tree.