NetworkTransform is pretty useless component. For example there is no way to reach smooth movement with Character Controller. Is it really that hard to provide us with nice and smooth solution, not this jerking bullshit?
I was going to come back here today and say I solved the issue. I removed the NetworkTransform and synced things manually with Rpc functions. It uses less network traffic and ends up with way better results lol.
You can write your own class using almost the same code as the one you see in NetworkTransform, but with your own interpolation in Update. I did it because it currently has no interpolation for SyncTransform, but you can use it as example for your own needs.
It also serializes some other stuff unrelated to movement (navagent’s destination) and has a few other lines that will be useless to your project, but you can just cut them out.
2250213–150357–MobaTransform.cs (9.35 KB)
@Glabrezu that’s an interesting idea. The issue for me is that interpolation does not look correct in a grid based game
It causes people to sometimes move diagonally when they should only move in 4 directions.Having an rpc update input and position has the least noticeable desync for grid based movements.
When I can go back to physics based movements I’ll see if networktransform has improved. The issue I saw with all of these demos is that if you take the client and go towards a wall, it always hits the wall first on the server so your client bounces off of nothing. If it’s that easy to desync then it’s not good ![]()
Hi!
I am trying to modify the lobby example file for my game project lobby system… everything looks fine and working okay… but for some reason, the host can see all the clients player game objects but the clients only see themselves and the host …not each other… please help !
Hello.
I’ve updated to Unity 5.1.3f1 and now I’m getting
UNet Client Disconnect Error: Timeout
UnityEngine.Networking.NetworkIdentity:UNetStaticUpdate()
error when trying to use network latency simulation. I’ve tried it on the “move” project.
UNET still working for me in 5.1.3f1, maybe something got deprecated in the example?
Could @seanr include your MOBA-like sample project, and attach the ZIP file to the top post? Thanks.
Could be. But I’m getting similar problem after updating to newer version.
To be precise I’m getting error described here . First I got it in my project. Then I decided to check if this problem exists in sample projects.
Too bad there is no fully functional example from unity. I mean client side prediction and server-client reconciliation.
What functions are you using? I am able to use syncvars, hooks, client rpcs and commands without issue. That’s all I’m really making use of. The built in stuff for other things, like network transform, is way to buggy even in ‘stable’ versions of unity.
I’m using Commands and syncvars with hooks.
Here take a look in this thread. The point is that everything was fine before updating to latest unity.
Hey there,
When I use the LobbyManager here, I’m able to succesfully load into the game, but this time, my players won’t spawn at Spawn Points with NetworkStartPosition component. Actually, first player is succesfully placed at the right position, but second one spawns at 0,0,0 which is not where my spawn points are. Previously when I used only Network Manager, I was able to spawn both my players at both spawn points.
I have quite a annoying problem. I’ve been trying to work around it for a while now… When even using the NetworkManager HUD example on the player disconnecting and reconnecting I get the following error. The only solution is to restart the client game and it works again.
“ArgumentException: An element with the same key already exists in the dictionary.
System.Collections.Generic.Dictionary2[UnityEngine.Networking.Types.NetworkID,UnityEngine.Networking.Types.NetworkAccessToken].Add (NetworkID key, UnityEngine.Networking.Types.NetworkAccessToken value) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:404) UnityEngine.Networking.Utility.SetAccessTokenForNetwork (NetworkID netId, UnityEngine.Networking.Types.NetworkAccessToken accessToken) (at C:/buildslave/unity/build/Runtime/Networking/Managed/UNETTypes.cs:119) UnityEngine.Networking.NetworkManager.OnMatchJoined (UnityEngine.Networking.Match.JoinMatchResponse matchInfo) (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkManager.cs:1010) UnityEngine.Networking.Match.NetworkMatch+<ProcessMatchResponse>c__Iterator01[UnityEngine.Networking.Match.JoinMatchResponse].MoveNext () (at C:/buildslave/unity/build/Runtime/Networking/Managed/MatchMakingClient.cs:302)”
@ I’m able to disconnect and reconnect if I use “StopHost” on both the client and server. I don’t use the HUD. I think the hud uses the client disconnect & server disconnect and for whatever reason that doesn’t properly shut down the server. If you simply call stop host on anyone who leaves you should be fine.
@Tomnnn Thanks I’ve tried that already as you can see in the following code:
if (_Menu_Loc == 5)
{
if (GUI.Button(new Rect((Screen.width / 2) - 290, (Screen.height / 2) + 160, 580, 25), "Leave"))
{
GetComponent<NetworkManager>().StopHost();
_Menu_Loc = 1;
}
}
else
{
if (GUI.Button(new Rect((Screen.width / 2) - 290, (Screen.height / 2) + 160, 580, 25), "Stop Hosting"))
{
GetComponent<NetworkManager>().StopHost();
_Menu_Loc = 1;
}
}
So if you’re a client and press the leave button it should be calling stop host. But it doesnt seem to for whatever reason. Could it be due to me doing this on the GUI thread? I noticed when this is run the player object is still running on server and then when you try to reconnect you’re actually still connected in the first place.
The StopHost on the host does stop that though and works.
I’ve also tried DropConnection. StopClient. StopMatchMaker… ect ect none seem to work. Except a game restart which kills the connection.
I imagine it would normally work but the player object being left in the server has your networkid already (or something like that). I haven’t seen networkmanager used with getcomponent. I think I tried that and it didn’t work. Generally people (in my experience) extendthe networkmanager and then just called StopHost or this.StopHost. I doubt that’s the issue but who knows, really.
If a player object is being left behind then something is definitely not working correctly.
Well heres the whole messy script. I don’t know whats up but its something to do with disconnecting. Can you try adding this script to a networkmanager with an empty object with identity for spawning? Maybe its just me?
using UnityEngine;
using System.Collections;
using UnityEngine.Networking;
public class EOMO_Manager : MonoBehaviour
{
public string _Username = "Username";
int _Menu_Loc = 0;
string _GameName = "Default";
void Start()
{
}
void OnGUI()
{
if (GetComponent<NetworkManager>().matchMaker == null)
{
GetComponent<NetworkManager>().StartMatchMaker();
}
if (_Menu_Loc == 0)
{
GUI.Box(new Rect((Screen.width / 2) - 110, (Screen.height / 2) - 110, 220, 140), GUIContent.none);
GUI.Label(new Rect((Screen.width / 2) - 100, (Screen.height / 2) - 100, 200, 25), "Login");
_Username = GUI.TextField(new Rect((Screen.width / 2) - 100, (Screen.height / 2) - 75, 200, 25), _Username);
if (GUI.Button(new Rect((Screen.width / 2) - 100, (Screen.height / 2) - 25, 200, 25), "Start"))
_Menu_Loc = 1;
}
else if (_Menu_Loc == 1)
{
GUI.Box(new Rect((Screen.width / 2) - 110, (Screen.height / 2) - 110, 220, 140), GUIContent.none);
GUI.Label(new Rect((Screen.width / 2) - 100, (Screen.height / 2) - 100, 200, 25), _Username + ", Play the Game");
if (GUI.Button(new Rect((Screen.width / 2) - 100, (Screen.height / 2) - 55, 200, 25), "Host Game"))
_Menu_Loc = 2;
if (GUI.Button(new Rect((Screen.width / 2) - 100, (Screen.height / 2) - 25, 200, 25), "View Games"))
{
GetComponent<NetworkManager>().matchMaker.ListMatches(0, 20, "", GetComponent<NetworkManager>().OnMatchList);
_Menu_Loc = 3;
}
}
else if (_Menu_Loc == 2)
{
GUI.Box(new Rect((Screen.width / 2) - 110, (Screen.height / 2) - 110, 220, 140), GUIContent.none);
GUI.Label(new Rect((Screen.width / 2) - 100, (Screen.height / 2) - 100, 200, 25), "Hosting - " + _GameName);
_GameName = GUI.TextField(new Rect((Screen.width / 2) - 100, (Screen.height / 2) - 75, 200, 25), _GameName);
if (GUI.Button(new Rect((Screen.width / 2) - 100, (Screen.height / 2) - 25, 200, 25), "Host"))
{
HostGame();
_Menu_Loc = 4;
}
}
else if (_Menu_Loc == 3)
{
GUI.Box(new Rect((Screen.width / 2) - 110, (Screen.height / 2) - 110, 220, 140), GUIContent.none);
GUI.Label(new Rect((Screen.width / 2) - 100, (Screen.height / 2) - 100, 200, 25), "Avaiable Games ");
int i = 0;
if (GetComponent<NetworkManager>().matches != null)
{
foreach (var _Match in GetComponent<NetworkManager>().matches)
{
if (GUI.Button(new Rect((Screen.width / 2) - 100, ((Screen.height / 2) - 70) + 30 * i, 200, 25), "Join Match:" + _Match.name))
{
GetComponent<NetworkManager>().matchName = _Match.name;
GetComponent<NetworkManager>().matchSize = (uint)_Match.currentSize;
GetComponent<NetworkManager>().matchMaker.JoinMatch(_Match.networkId, "", GetComponent<NetworkManager>().OnMatchJoined);
_Menu_Loc = 5;
}
i++;
}
}
if (GUI.Button(new Rect((Screen.width / 2) - 100, ((Screen.height / 2) - 0), 200, 25), "Back"))
{
_Menu_Loc = 1;
}
}
else if (_Menu_Loc == 4 || _Menu_Loc == 5)
{
GUI.Box(new Rect((Screen.width / 2) - 300, (Screen.height / 2) - 200, 600, 400), GUIContent.none);
GUI.Label(new Rect((Screen.width / 2) - 290, (Screen.height / 2) - 190, 580, 25), "Game Lobby");
GameObject[] allObjects = GameObject.FindObjectsOfType<GameObject>();
int i = 0;
foreach (GameObject go in allObjects)
{
if (go.activeInHierarchy)
{
if (go.name.Contains("PLAYER"))
{
GUI.Button(new Rect((Screen.width / 2) - 290, ((Screen.height / 2) - 130) + 30*i, 200, 25), go.name.Replace("PLAYER_", "").Replace("HOST_", ""));
i++;
}
else if (go.name.Contains("HOST"))
{
GUI.Button(new Rect((Screen.width / 2) - 290, ((Screen.height / 2) - 160), 200, 25), go.name.Replace("PLAYER_", "").Replace("HOST_", "(") + ")");
}
}
}
if (_Menu_Loc == 5)
{
if (GUI.Button(new Rect((Screen.width / 2) - 290, (Screen.height / 2) + 160, 580, 25), "Leave"))
{
GetComponent<NetworkManager>().StopClient();
_Menu_Loc = 1;
}
}
else
{
if (GUI.Button(new Rect((Screen.width / 2) - 290, (Screen.height / 2) + 160, 580, 25), "Stop Hosting"))
{
GetComponent<NetworkManager>().StopHost();
_Menu_Loc = 1;
}
}
}
}
void HostGame()
{
GetComponent<NetworkManager>().matchMaker.CreateMatch(_GameName, 100, true, "", GetComponent<NetworkManager>().OnMatchCreate);
}
}
I wouldn’t know what to do since I don’t use matchmaker I guess
Maybe that’s what is causing the issue. With UNET, the less built in things you use, the better. I usually do something like…
class GameManager : NetworkManager {
bool connected = false;
void Update(){
if(!connected)
{
if(Input.GetKeyDown(KeyCode.Alpha1))
{
StartHost();
connected = true;
}
else if(Input.GetKeyDown(KeyCode.Alpha2))
{
StartClient();
connected = true;
}
}
if(connected)
{
if(Input.GetKeyDown(KeyCode.Alpha3))
{
Disconnect();
}
}
}//Update
void Disconnect()
{
StopHost();
connected = false;
}
}
That’s pseudo code for the most part but it’s how I test my connections.
Run 1 instance in the editor and another as a build. Press 1 in your editor and 2 in your build. You should see things connect in the server. Then press 3 in your build and see if the client disconnects on the server.
@Tomnnn Isnt this for local connections though? Which I know works. I’m wondering if I should do all of the server related things off the GUI thread using proper callback’s ect instead of assuming things are working, which it does currently. It may fix things. I hope. I’ll get back to you when done.
@Tomnnn Ok first I changed logging mode to developer and I can see its calling StopClient() as is “Shutting down Client 0”. Hmm strange.
I’m wondering if I need the host to detect the connection has closed and delete the controller. So it can be added again but I dont know how to go about that…
This just gets weirder. Running server I can see when the client leaves that is says "Server Lost Client:1. OnLocalObjDestroy. And its removed it? Lol whats going on here…