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.
if (TNServerInstance.Start(TcpPort, UdpPort, null))
{
TNManager.Connect();
}
4. When connected, join a channel.
private void OnNetworkConnect(bool success, string message)
{
if (success)
{
TNManager.JoinChannel(ChannelId, "Main", false, 4, "pw", true);
}
}
5. When the channel has been joined, create the player
private void OnNetworkJoinChannel(int channelid, bool success, string message)
{
if (success)
{
Main.Unit.CreatePlayer();
}
}
In the Unit Manager
public void CreatePlayer()
{
var prefabPath = Main.Player.PlayerType.ToString();
TNManager.Instantiate(TnetManager.ChannelId, "CreateCharacterModel", prefabPath, false, Vector3.zero, Main.Player.PlayerName);
}
[RCC][UsedImplicitly]
static GameObject CreateCharacterModel(GameObject prefab, Vector3 position, string playerName)
{
var go = prefab.Instantiate();
var controller = prefab.GetComponent<UnitController>();
controller.SetCharacter(playerName, controller.Type, position);
return go;
}
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?