I know we have touched all around this question, and some dipped in and back out of it, i was wondering if there has been a valid solution for this situation.
Situation: FPS multiplayer game. We want to store data such as, who’s on which team, the count etc… Theoretically there will be a game master script tied to a player who enters the room. When the player leaves the room or exits the game for any reason, the game master script finds a new player.
All of this works well, however, we are running into the issue of a player leaving the game between scenes. Since the info was temporarily stored then the game will cease to know who, what, when, and where before the next scene is loaded. We tried utilizing a constant scene, but that creates alot of trouble trying to keep it static.
Agreed, but is keeping that persistent object as simple as it sounds? I though in order to keep a persistent object, we would need to have a persistent scene?! If not, how does one store information on an persistent object. I understand what your saying, but im not sure if this can be done, and store the proper values that the scene requires. Please explain just a tad bit more. Thank you.
For instance, when you “leave” a scene, it destroys everything on it. This would destroy that object. If you have a persistent object, then where is the information stored?
Make a GameObject called something. This will be your persistent object so keep the connection scripts on this object. Then in one of your scripts do this:
void Awake()
{
DontDestroyOnLoad(gameObject);
}
or
function Awake()
{
DontDestroyOnLoad(gameObject);
}
So now this object will NEVER be destroyed if you switch scene. If you keep information such as Username’s on this object then other scripts can “leech” that information for their own needs.