Hide sprite via button press across .TSCN's.

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

Simple thing really but does not seam to work.

I have a game.tscn with a sprite and a button.
I have another UIInterface.tscn with a ui environment.

Press the button on the game.tscn and the code goes to

func _on_Button_pressed():
get_node(“LogoSprite”).set_hidden()
visible = true

The tree has the 2DNode (Game) a couple nodes for other items and a welcomescreen node that has the sprite in it.

Every time you press the button error comes up.
NODE NOT FOUND: LOGOSPRITE
I have tried copying the node path “WelcomeScreen/BackgroundScr/LogoSprite” still dont work
I have tried .hidden(), .visible = false, everything returns the same error.

Is it because the button goes from GAME.TSCN signal to UIINTERFACE.TSCN?

I have googled it, check video tutorials, check through godot website and forums, NOTHING!

Please let me know if you have a clue of what can be going on, this is getting to the point I want to return to Unity but I love the small and easy program size of Godot and do not want to have to go back.

:bust_in_silhouette: Reply From: njamster

I have tried .hidden(), .visible = false, everything returns the same error.

Obviously. The error is about a non-existent node, not a non-existent method. If you call a different method on the same node, the node still doesn’t exist.

From your description I get your tree looks somewhat like this?

- UIInterface
  - Game
    - Button
  - ...
  - WelcomeScreen
    - BackgroundSrc
      - LogoSprite

In that case, the path "WelcomeScreen/BackgroundScr/LogoSprite" would be the correct, if the script containing the callback-method on_Button_pressed is attached to the UIInterface-node. However, if it’s attached to the Game-node it would be:

get_node("../WelcomeScreen/BackgroundScr/LogoSprite")

The node path is relative to the node the script is attached to. So you have to first navigate to the Game-nodes parent-node “UIInterface” using .., which is just the short-hand form of get_parent(). The following is equivalent:

get_parent().get_node("WelcomeScreen/BackgroundScr/LogoSprite")

get_node(“…/WelcomeScreen/BackgroundScr/LogoSprite”).hide()
This fixed the issue. Now I understand, I was reading up on nodes but did not quite understand it fully. I had the understanding that root node and anything under that node should be able to be accessed just right of the bat and not need to indicate it is in root as your already there :slight_smile:
Many thank you’s this saved a lot of frustration and headaches.

CoreCoder | 2020-05-11 16:11