Author Topic: Clear persistant data.  (Read 1933 times)

Kerozard

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 17
    • View Profile
Clear persistant data.
« on: September 01, 2017, 12:04:25 AM »
I have only been playing with TNet3 for a few houra. I am trying to put together a quick prototype of a game.

I have the following steps in place:

1. Start the game in the Unity Editor
2. Enter Name and select a character class.
3. Start the server and connect to it.
  1. if (TNServerInstance.Start(TcpPort, UdpPort, null))
  2. {
  3.     TNManager.Connect();
  4. }
  5.  
4. When connected, join a channel.
  1. private void OnNetworkConnect(bool success, string message)
  2. {
  3.     if (success)
  4.     {
  5.         TNManager.JoinChannel(ChannelId, "Main", false, 4, "pw", true);
  6.     }
  7. }
  8.  
5. When the channel has been joined, create the player
  1. private void OnNetworkJoinChannel(int channelid, bool success, string message)
  2. {
  3.     if (success)
  4.     {
  5.         Main.Unit.CreatePlayer();
  6.     }
  7. }
  8.  
In the Unit Manager
  1. public void CreatePlayer()
  2. {
  3.     var prefabPath = Main.Player.PlayerType.ToString();
  4.     TNManager.Instantiate(TnetManager.ChannelId, "CreateCharacterModel", prefabPath, false, Vector3.zero, Main.Player.PlayerName);
  5. }
  6.  
  7. [RCC][UsedImplicitly]
  8. static GameObject CreateCharacterModel(GameObject prefab, Vector3 position, string playerName)
  9. {
  10.     var go = prefab.Instantiate();
  11.     var controller = prefab.GetComponent<UnitController>();
  12.  
  13.     controller.SetCharacter(playerName, controller.Type, position);
  14.     return go;
  15. }
  16.  

So far so good, the prefab gets spawned and placed into the scene on all connected clients. Through added debug output I can also see that the name is set correctly. But when I name my character "Michael", then stop the Unity player, restart it, then name myself "Patrick", I can see the name "Patrick" set correctly, but it is then being overwritten with "Michael", the name I entered the last time I started a match. This leads me to believe that this is a persistence issue. My values get overwritten by values from the last session.

How do I make sure to have a clean start each time I start the player?

Kerozard

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 17
    • View Profile
Re: Clear persistant data.
« Reply #1 on: September 01, 2017, 06:54:55 AM »
Alright, please disregard this. It was my fault. I was instantiating the prefab in the RCC, but calling the method in which I set the instance values not on the instance, but on the prefab thus changing the prefab values which then persisted until the next start when a new instance was instantiated. :-(