How to get an Image the player have selected in different scene

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

Hey guys,

Hopefully, someone will be able to help me out. So right now I have a Sprite with the customized beard (beard is being represented as Sprite inside of Sprite, from this tutorial - https://www.youtube.com/watch?v=Lh2H-O5-VAo&t=220s ). The player can select one out of 3 options. I would like to present the Sprite that the player has selected with the specific beard in a different scene. I will leave a code that I have right now. Thanks and have a good day.

CODE EXAMPLE — Imgur: The magic of the Internet

:bust_in_silhouette: Reply From: jgodfrey

The right answer probably depends on the details of your project. Without knowing more, one way to do it would be:

  • Create a Singleton script to maintain global game state
  • Add a variable to that script to store your selected beard information
  • Once the beard has been selected, store it in the singleton script
  • Change scenes
  • In the new scene, retrieve the stored beard value from the singleton script

This is a very frequent question which keeps getting asked in various ways. Here is another one with some info about singletons: Is it possible to make a variable that keep's the value assigned to it across different scenes? - Archive - Godot Forum

Zylann | 2020-03-09 19:27

I see. Thanks a lot for your help!

HashTag | 2020-03-10 07:42