How do i changes nodes within a scene from another scene?

Godot 4 3D

How do i changes nodes within a scene from another scene?

Hello. Im new to Godot. I have basic understanding of it.
I want to know how to add a hat onto my player after I buy it from the shop.
I made a player that has different hat nodes in the player’s node tree, however the visibility of them is turned off. I want to know if there’s a way to send a signal from one scene(scene 1) to another scene (scene 2).

I want to make it where when i click a ‘buy button’ in the ‘shop scene’, I could send a signal to the ‘player scene’ that would switch the visibility of the hat node to true.

I tried putting the hat node into a group and then having a function within the script of the player to turn it on:

get_tree().call_group( “hat_group”, “hat_on” )

it didn’t work saying that my ‘call_group()’ has a null instance and i couldn’t find out why.

If anybody has any input, it would be greatly appreciated.

My game is a a a hyper casual mobile game. The best way to put it is like Subway Surfers.

Where you start at the home page:
(click shop)
(buy new character)
(back to home page)
and now in the gameplay, you are the new character.
My home page is the main scene.

Shop node tree:
the shop is a U.I scene

|Shop
|-- Hat (texturerec)
|-- Buy (button)

Player node tree:
the player is a 3d scene

|Player
|-- Mesh
|-- CollisionShape
|-- Hat (mesh) (visibile off)

So i was wondering if it’s possible to when i click the ‘buy button’ it could send a signal outside of its own node tree, to the ‘Player scene’ that could change the ‘hat visible on’. Hope this provides some information…

I think it would be best to get a reference of the player to the shop somehow. You may have to show more of your shop script for specific advice. Maybe your scene tree too.

You options are as follows, in an order I usually go down

  1. Signal connected function such as collisions
  2. @export variable
  3. Groups
  4. Autoload
  5. hard-coded NodePath

If your shop is set up in a specific area the player must enter, then try to store the colliding body upon contact.

If your shop is always in a scene with the player, then an @export can be assigned to the player.

Otherwise I consider the last three fairly messy. You can add the player to a group and call get_tree().get_first_node_in_group("Player").

1 Like

Thanks for your response, ill give more detail about it.
My game is a a a hyper casual mobile game. The best way to put it is like Subway Surfers.

Where you start at the home page:
(click shop)
(buy new character)
(back to home page)
and now in the gameplay, you are the new character.
My home page is the main scene.

Shop node tree:
the shop is a U.I scene

|Shop
|-- Hat (texturerec)
|-- Buy (button)

Player node tree:
the player is a 3d scene

|Player
|-- Mesh
|-- CollisionShape
|-- Hat (mesh) (visibile off)

So i was wondering if it’s possible to when i click the ‘buy button’ it could send a signal outside of its own node tree, to the ‘Player scene’ that could change the ‘hat visible on’. Hope this provides some information…

I’d argue for keeping cosmetic information in a save file, if your player is created in the game scene then load the cosmetic data upon loading the player.

A config file may be a good fit

1 Like

Thank you for your help. I’ll give it a try.