Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags
(1 edit)

There are many, many ways you can do this depending on the complexity you need, but first you should know why that data isn't persisting currently.  It sounds like you are assigning the player's name to some MonoBehaviour attached to a GameObject in the scene.  You can do that, but (by default) when you unload a scene, every object in the scene is destroyed and its data is lost.  Even if you have e.g. a copy of the same prefab in every scene, each one is still a separate object with its own state.

A simple way to do this would be to create a ScriptableObject containing variables for the player's name and whatever other persistent data you need (health / ammo / etc) and set the values there.  Then anywhere you reference that ScriptableObject in the application, you will see the same values, because there is only ever one copy of a ScriptableObject and it is not tied to a scene.  To get the data to persist after closing the game, you would have to write those values to a file when the player saves the game, then read them from the file when the player loads the game.

Hey, thanks for your help! It worked and gave me a way to do other stuff like ammo, life tracking, reloading, etc. I really appreciate your help.

Although, If you don’t mind, I have been now stuck to another bug. You see that while using instantiate for patrol enemies, only one of them follows the player. The other enemies just move around until the enemy which is following the player is destroyed. Is there a way to go around this hustle?

How did you implement this?