Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

UNet Sample Projects

Discussion in 'UNet' started by seanr, Jun 9, 2015.

  1. GenaSG

    GenaSG

    Joined:
    Apr 19, 2014
    Posts:
    111
    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.
     
  2. OnurYIL

    OnurYIL

    Joined:
    Nov 4, 2013
    Posts:
    140
    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.
     
  3. Deleted User

    Deleted User

    Guest

    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.Dictionary`2[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__Iterator0`1[UnityEngine.Networking.Match.JoinMatchResponse].MoveNext () (at C:/buildslave/unity/build/Runtime/Networking/Managed/MatchMakingClient.cs:302)"
     
  4. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    @Magnet_man16 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.
     
  5. Deleted User

    Deleted User

    Guest

    @Tomnnn Thanks I've tried that already as you can see in the following code:

    Code (CSharp):
    1. if (_Menu_Loc == 5)
    2.             {
    3.                 if (GUI.Button(new Rect((Screen.width / 2) - 290, (Screen.height / 2) + 160, 580, 25), "Leave"))
    4.                 {
    5.                  
    6.                     GetComponent<NetworkManager>().StopHost();
    7.                     _Menu_Loc = 1;
    8.                 }
    9.             }
    10.             else
    11.             {
    12.                 if (GUI.Button(new Rect((Screen.width / 2) - 290, (Screen.height / 2) + 160, 580, 25), "Stop Hosting"))
    13.                 {
    14.                     GetComponent<NetworkManager>().StopHost();
    15.                     _Menu_Loc = 1;
    16.                 }
    17.             }
    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.
     
  6. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    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.
     
  7. Deleted User

    Deleted User

    Guest

    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?

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEngine.Networking;
    4.  
    5. public class EOMO_Manager : MonoBehaviour
    6. {
    7.     public string _Username = "Username";
    8.  
    9.     int _Menu_Loc = 0;
    10.     string _GameName = "Default";
    11.  
    12.     void Start()
    13.     {
    14.      
    15.     }
    16.  
    17.     void OnGUI()
    18.     {
    19.         if (GetComponent<NetworkManager>().matchMaker == null)
    20.         {
    21.             GetComponent<NetworkManager>().StartMatchMaker();
    22.         }
    23.  
    24.         if (_Menu_Loc == 0)
    25.         {
    26.             GUI.Box(new Rect((Screen.width / 2) - 110, (Screen.height / 2) - 110, 220, 140), GUIContent.none);
    27.             GUI.Label(new Rect((Screen.width / 2) - 100, (Screen.height / 2) - 100, 200, 25), "Login");
    28.             _Username = GUI.TextField(new Rect((Screen.width / 2) - 100, (Screen.height / 2) - 75, 200, 25), _Username);
    29.             if (GUI.Button(new Rect((Screen.width / 2) - 100, (Screen.height / 2) - 25, 200, 25), "Start"))
    30.                 _Menu_Loc = 1;
    31.         }
    32.         else if (_Menu_Loc == 1)
    33.         {
    34.             GUI.Box(new Rect((Screen.width / 2) - 110, (Screen.height / 2) - 110, 220, 140), GUIContent.none);
    35.             GUI.Label(new Rect((Screen.width / 2) - 100, (Screen.height / 2) - 100, 200, 25), _Username + ", Play the Game");
    36.             if (GUI.Button(new Rect((Screen.width / 2) - 100, (Screen.height / 2) - 55, 200, 25), "Host Game"))
    37.                 _Menu_Loc = 2;
    38.             if (GUI.Button(new Rect((Screen.width / 2) - 100, (Screen.height / 2) - 25, 200, 25), "View Games"))
    39.             {
    40.                 GetComponent<NetworkManager>().matchMaker.ListMatches(0, 20, "", GetComponent<NetworkManager>().OnMatchList);
    41.                 _Menu_Loc = 3;
    42.             }
    43.         }
    44.         else if (_Menu_Loc == 2)
    45.         {
    46.             GUI.Box(new Rect((Screen.width / 2) - 110, (Screen.height / 2) - 110, 220, 140), GUIContent.none);
    47.             GUI.Label(new Rect((Screen.width / 2) - 100, (Screen.height / 2) - 100, 200, 25), "Hosting - " + _GameName);
    48.             _GameName = GUI.TextField(new Rect((Screen.width / 2) - 100, (Screen.height / 2) - 75, 200, 25), _GameName);
    49.             if (GUI.Button(new Rect((Screen.width / 2) - 100, (Screen.height / 2) - 25, 200, 25), "Host"))
    50.             {
    51.                 HostGame();
    52.                 _Menu_Loc = 4;
    53.             }
    54.         }
    55.         else if (_Menu_Loc == 3)
    56.         {
    57.             GUI.Box(new Rect((Screen.width / 2) - 110, (Screen.height / 2) - 110, 220, 140), GUIContent.none);
    58.             GUI.Label(new Rect((Screen.width / 2) - 100, (Screen.height / 2) - 100, 200, 25), "Avaiable Games ");
    59.             int i = 0;
    60.             if (GetComponent<NetworkManager>().matches != null)
    61.             {
    62.                 foreach (var _Match in GetComponent<NetworkManager>().matches)
    63.                 {
    64.                     if (GUI.Button(new Rect((Screen.width / 2) - 100, ((Screen.height / 2) - 70) + 30 * i, 200, 25), "Join Match:" + _Match.name))
    65.                     {
    66.                         GetComponent<NetworkManager>().matchName = _Match.name;
    67.                         GetComponent<NetworkManager>().matchSize = (uint)_Match.currentSize;
    68.                         GetComponent<NetworkManager>().matchMaker.JoinMatch(_Match.networkId, "", GetComponent<NetworkManager>().OnMatchJoined);
    69.                         _Menu_Loc = 5;
    70.                     }
    71.                     i++;
    72.                 }
    73.             }
    74.  
    75.             if (GUI.Button(new Rect((Screen.width / 2) - 100, ((Screen.height / 2) - 0), 200, 25), "Back"))
    76.             {
    77.                 _Menu_Loc = 1;
    78.             }
    79.  
    80.         }
    81.         else if (_Menu_Loc == 4 || _Menu_Loc == 5)
    82.         {
    83.             GUI.Box(new Rect((Screen.width / 2) - 300, (Screen.height / 2) - 200, 600, 400), GUIContent.none);
    84.             GUI.Label(new Rect((Screen.width / 2) - 290, (Screen.height / 2) - 190, 580, 25), "Game Lobby");
    85.  
    86.             GameObject[] allObjects = GameObject.FindObjectsOfType<GameObject>();
    87.             int i = 0;
    88.             foreach (GameObject go in allObjects)
    89.             {
    90.                 if (go.activeInHierarchy)
    91.                 {
    92.                     if (go.name.Contains("PLAYER"))
    93.                     {
    94.                         GUI.Button(new Rect((Screen.width / 2) - 290, ((Screen.height / 2) - 130) + 30*i, 200, 25), go.name.Replace("PLAYER_", "").Replace("HOST_", ""));
    95.                         i++;
    96.                     }
    97.                     else if (go.name.Contains("HOST"))
    98.                     {
    99.                         GUI.Button(new Rect((Screen.width / 2) - 290, ((Screen.height / 2) - 160), 200, 25), go.name.Replace("PLAYER_", "").Replace("HOST_", "(") + ")");
    100.                     }
    101.                  
    102.                 }
    103.             }
    104.  
    105.             if (_Menu_Loc == 5)
    106.             {
    107.                 if (GUI.Button(new Rect((Screen.width / 2) - 290, (Screen.height / 2) + 160, 580, 25), "Leave"))
    108.                 {
    109.                  
    110.                     GetComponent<NetworkManager>().StopClient();
    111.                     _Menu_Loc = 1;
    112.                 }
    113.             }
    114.             else
    115.             {
    116.                 if (GUI.Button(new Rect((Screen.width / 2) - 290, (Screen.height / 2) + 160, 580, 25), "Stop Hosting"))
    117.                 {
    118.                     GetComponent<NetworkManager>().StopHost();
    119.                     _Menu_Loc = 1;
    120.                 }
    121.             }
    122.         }
    123.     }
    124.  
    125.     void HostGame()
    126.     {
    127.         GetComponent<NetworkManager>().matchMaker.CreateMatch(_GameName, 100, true, "", GetComponent<NetworkManager>().OnMatchCreate);
    128.     }
    129. }
    130.  
     
  8. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    I wouldn't know what to do since I don't use matchmaker I guess :p Maybe that's what is causing the issue. With UNET, the less built in things you use, the better. I usually do something like...

    Code (CSharp):
    1. class GameManager : NetworkManager {
    2.  
    3. bool connected = false;
    4.  
    5. void Update(){
    6.     if(!connected)
    7.     {
    8.          if(Input.GetKeyDown(KeyCode.Alpha1))
    9.         {
    10.              StartHost();
    11.              connected = true;
    12.         }
    13.         else if(Input.GetKeyDown(KeyCode.Alpha2))
    14.         {
    15.              StartClient();
    16.              connected = true;
    17.          }
    18.     }
    19.  
    20. if(connected)
    21.     {
    22.          if(Input.GetKeyDown(KeyCode.Alpha3))
    23.         {
    24.              Disconnect();
    25.         }
    26.     }
    27.  
    28. }//Update
    29.  
    30. void Disconnect()
    31. {
    32.     StopHost();
    33. connected = false;
    34. }
    35. }
    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.
     
  9. Deleted User

    Deleted User

    Guest

    @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.
     
  10. Deleted User

    Deleted User

    Guest

    @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...
     
  11. Deleted User

    Deleted User

    Guest

    Just tried the network starter demo and it comes up with same error. On connecting and disconnecting. If you connect again you get:

    "ArgumentException: An element with the same key already exists in the dictionary.
    System.Collections.Generic.Dictionary`2[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__Iterator0`1[UnityEngine.Networking.Match.JoinMatchResponse].MoveNext () (at C:/buildslave/unity/build/Runtime/Networking/Managed/MatchMakingClient.cs:302)"
     
  12. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    Like I said, using the built in stuff with UNET [right now] is beyond a bad idea. My sort-of code sample was for local testing yes, but I was just wondering if connecting again on localhost would give you trouble. The bug is that your client isn't being destroyed on the server.

    Easy way to confirm the bug - quit the application on the client instead of manually disconnecting. That should fire a proper disconnect so you can connect again (after booting up another client)
     
  13. mbowen89

    mbowen89

    Joined:
    Jan 21, 2013
    Posts:
    639
    So it's probably not feasible to release a game with unet in the next 2-3 months?
     
  14. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    Using the network gui & network transforms? Probably not in a competitive game. The buggy movement and position interpolation probably wouldn't be as much of an issue for a co-op game.

    If you are only using syncvars, hooks, extend the network manager, make good use of commands and clientrpcs... then you're fine. You just have to write really good interpolation and movement code if your game is going to be competitive in any way... besides a racing game.

    Player makes an input => input differs from server syncvar => player invokes command to change syncvar => syncvar hook is called on all copies of the client that updates movement

    Do that and you can make any game with UNET right now. Just don't rely on the network transform. Matchmaker I haven't tried, but clearly some users are having trouble with it.
     
  15. mbowen89

    mbowen89

    Joined:
    Jan 21, 2013
    Posts:
    639
    Ok, I'll do my best to see if I can get it to play well enough at this stage. It's a mobile hunting game, the multiplayer part being able to run around the terrain together hunting... So just syncing animal and player position really, not even competing against each other.
     
  16. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    No troubles then :D Just put a syncvar on your animals and players that determines how it's moving. Like a synced vector3. When ever it changes, tell everyone. You can also send position data to snap things when they start to desync. That's my approach.

    Send input & position via commands, compare the sent position with the position on the server, if the player and server copy of the player are more than 0.5 units apart, I snap one to the other's position. The size should depend on how large your objects are I guess or how far of a snap you want to have.
     
  17. MD_Reptile

    MD_Reptile

    Joined:
    Jan 19, 2012
    Posts:
    2,664
    Would be great to have more examples. Are there any other public projects out there I haven't found?
     
  18. Deleted User

    Deleted User

    Guest

  19. MD_Reptile

    MD_Reptile

    Joined:
    Jan 19, 2012
    Posts:
    2,664
    Oh wow, good collection there! Thanks @rikey
     
  20. tkoknordic

    tkoknordic

    Joined:
    Jan 31, 2013
    Posts:
    93
  21. asperatology

    asperatology

    Joined:
    Mar 10, 2015
    Posts:
    981
  22. Chrispins

    Chrispins

    Joined:
    Dec 9, 2014
    Posts:
    15
    Do you think that using SyncVars and commands to sync object positions creates about the same network traffic as that method you whipped up? I'm looking for the most efficient way to do this kind of thing without resorting to the legacy multiplayer features.
     
  23. asperatology

    asperatology

    Joined:
    Mar 10, 2015
    Posts:
    981
    Depending on where you put your [Commands] at. I only know what it will do, is it will spike up the network traffic no matter where you call your [Commands] to sync the SyncVars.
     
  24. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    The idea is that anything you do yourself will probably be better than networktransform. Networktransform can be configured to be called 30 times per second. If you sync any less than that and with less complex data then you're going to do much better.

    I sync movement vectors instead of position when I can. And when the movement is normalized, like being only able to move in 4 or 8 directions, I send a number 0-7 instead and translate that to a direction on the client. I've done everything I can to minimize latency. I'll have to try again sometime soon and see if the system is any better.

    One trick I have learned is that you can reduce jittery motion by only syncing beyond a threshold. Have the client check the distance between their current position and their syncvar position. If the distance is greater than a certain amount then set the positions according to whatever you think is best.

    1 Set local position to syncvar position - only the player experiences a movement bug
    2 Set syncvar position to local position - the other players and server see the player jump a short distance
    3 Set both positions to a point between the two - all players and server see the player take a short jump

    If the connection is reliable or you're in a competitive game, #1 is the best option. If you're in a cooperative game or your connection is bad then #2 is the best option.
     
    Chrispins and MD_Reptile like this.
  25. cariaga

    cariaga

    Joined:
    Feb 6, 2013
    Posts:
    13
    Network starter ERROR
    i'm unable to connect over the network when using the android device and the error i keep receiving when trying to connect is error 6 and sometimes error 11 i can't seam to pin point the exact problem
     
  26. enhawk

    enhawk

    Joined:
    Aug 22, 2013
    Posts:
    833
    Thanks for these, some problems:

    • "2Dshooter" is broken. Won't start, 2 errors in the console.
    • "Network Spawning" can't start Matchmaker games, error in console.
    • "Invaders" has no Matchmaker actions on the gui buttons.
    • "move" errors out when trying to start Matchmaker
    • "tanks" complains about multiple transforms and a missing object reference and errors out when trying to start any multiplayer
    I'd really like to learn how to make a lobby to replace the onGUI hud
     
    Last edited: Dec 8, 2015
  27. asperatology

    asperatology

    Joined:
    Mar 10, 2015
    Posts:
    981
    Please either make a new post, or file a bug report to Unity.

    MatchMaker relies on Unity Multiplayer Services. Unless you are already using Unity 5 Pro, I would suggest you to focus on LAN connections, until you decide the Multiplayer services is crucial to your game.
     
  28. enhawk

    enhawk

    Joined:
    Aug 22, 2013
    Posts:
    833
    I am using Unity Multiplayer Services on Pro. ;)

    Bit of an oxymoron isn't it? This is the uNet forum. I'm a mobile developer.
     
  29. asperatology

    asperatology

    Joined:
    Mar 10, 2015
    Posts:
    981
    Because I had the assumption that you aren't using Pro, and is more like me using Personal Edition. In fact, I don't even know if I'm using Unity 5 Education, or if Unity 5 Education is legible for Unity Services...

    The only thing I can point you to is to use LobbyManager, and you may have to do a bit of research on your part for features you require. I never used LobbyManager before, and because I'm not using a Pro version, I'm not well-versed with Unity Services.
     
    twobob likes this.
  30. tonyBkln

    tonyBkln

    Joined:
    Jul 9, 2015
    Posts:
    5
    Wonderful examples, thanks a lot!
     
  31. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    What? What is this madness? Have they been updated? Is unet a little better now?
     
  32. Munchy2007

    Munchy2007

    Joined:
    Jun 16, 2013
    Posts:
    1,732
    I've been getting to grips with Unity Networking for a few weeks now, and whilst initially it seemed impossible to reproduce what I could do with Photon, as things have 'clicked' and I have got my head around the way a server authoritative system works, I've found that it actually works very well. In fact I've found that there are a number of things that are easier to implement with Unity Networking compared with Photon.

    Admittedly there still seems to be a few bugs, and documentation is particularly poor in a lot of places. It's worth noting however, that a number of what I first thought of as bugs, actually turned out to be as a result of my misunderstanding of how things worked.

    I'm by no means a Photon networking expert, but having used both I've found that I already prefer Unity Networking, and as it continues to develop I can only imagine that preference will strengthen.
     
    Tomnnn likes this.
  33. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    @Munchy2007 if you do things yourself, there's no problem, sure... but @tonyBkln thanked them for the sample projects, which utilize the network transform component. You can start 2 instances of the project running on 127.0.0.1 and there's still - in that ideal networking environment - desync between the server and client lol
     
  34. Serhii-Horun

    Serhii-Horun

    Joined:
    Apr 12, 2015
    Posts:
    151
  35. asperatology

    asperatology

    Joined:
    Mar 10, 2015
    Posts:
    981
    Code (csharp):
    1. NetworkManager.useWebSockets = true;
     
  36. Serhii-Horun

    Serhii-Horun

    Joined:
    Apr 12, 2015
    Posts:
    151
    Yeah, I enabled webSockets. I can create local match, but I dont understand how I can find intenret match(matches list) and connect someone (not localy) in WebGL. MatchMaker doesn't work in WebGL
     
  37. asperatology

    asperatology

    Joined:
    Mar 10, 2015
    Posts:
    981
    MatchMaker not supported. For more information, please ask in a new thread.
     
  38. Serhii-Horun

    Serhii-Horun

    Joined:
    Apr 12, 2015
    Posts:
    151
  39. Ashkan_gc

    Ashkan_gc

    Joined:
    Aug 12, 2009
    Posts:
    1,116
    I have a lot of problems with syncvars when I have a mix of strings, ints and sturcts in my script in 5.3
     
  40. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    The data you're trying to sync should be as small as possible. Are you trying to sync a string over the network? Are you trying to sync a struct over the network?

    See what you can do to make changes so that you're only syncing ints. If these strings are from a set of known ones, maybe change it to an enum so you can sync with ints.
     
  41. Ashkan_gc

    Ashkan_gc

    Joined:
    Aug 12, 2009
    Posts:
    1,116
    They are small, the sting contains "h" and another is "" and the struct has only 3 floats

    If I get size errors then I can use a fragmented channel. The serialization gets messed up I guess.
     
  42. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    Ah. Either a 5.3 bug or a bug serializing your struct. Maybe you can log the variable on the server and see what's being sent?
     
  43. Ashkan_gc

    Ashkan_gc

    Joined:
    Aug 12, 2009
    Posts:
    1,116
    This is strange, actually the next time I did it, it worked. Maybe a code generation issue or something. As soon as Sean comes back to forum I want to ask him about when and how code gen happens, the bad thing is that it's done in IL and on DLLs so it's a little time consuming to debug but still worth taking a look at. However SyncListInt doesn't work , at least I could not make it work.
     
  44. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    Haha sometimes a small change that does nothing will have unity recompile... and maybe the bug went away in that time.
     
  45. Ashkan_gc

    Ashkan_gc

    Joined:
    Aug 12, 2009
    Posts:
    1,116
    Actually I have an issue still in a specific case which I could not reproduce in a minimal project. I get InDexOutOfRange exception when initializing object from syncvar message at client and I changed channel to ReliableFragmented as well but it didn't work. Should pin it down.
     
  46. jroto23

    jroto23

    Joined:
    Oct 19, 2015
    Posts:
    82
    I have been building off the NetworkStarter example. It works with one killer issue, after about a minute or so the client will get disconnected from the relay server. It's almost as it the client was intentionally dropped. The player who created the game does not get disconnected and can continue to play. Anyone else experiencing this?
     
  47. zKici

    zKici

    Joined:
    Feb 12, 2014
    Posts:
    438
    I'm certainly looking into using approach #1, thank you for these detailed explanations.

    I just started following the Unity networking tutorial, it works but it is using NetworkTransform (its horrible at this point), can you please provide me a script example how to sync the player's movement.

    Even if its using this simple script provided by the tut:

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using UnityEngine.Networking;
    4.  
    5. public class PlayerMove : NetworkBehaviour
    6. {
    7.     void Update()
    8.     {
    9.         if (!isLocalPlayer)
    10.             return;
    11.  
    12.         var x = Input.GetAxis("Horizontal")*0.1f;
    13.         var z = Input.GetAxis("Vertical")*0.1f;
    14.  
    15.         transform.Translate(x, 0, z);
    16.     }
    17. }
    18.  

    What I am trying to achieve is a moba-style game where the player is the host and allows up to 7 other players to join. So I would have to sync their positions as well as up to 3 projectiles/bullets per player per 10 seconds.

    On impact this will cause damage and/or add force to the impacted player. I am confident once I have a starting point I can make it as elaborate as needed myself.

    I've read a lot of mixed reviews regarding uNet, I hope this is possible to achieve, at this point is is moot.

    Thank you all.
     
  48. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    @zKici I have moved quite a bit away from unity in general at the moment. And when I return to it I doubt I will use unet very much at all. I'm doing a lot of ajax and server stuff for my job so I think I'd be better off running my own server solution and creating sockets with c# instead of a unity class.

    As for unet, all I can say is that my best attempt at it a few months ago was still a major failure haha. No networking solution is 100% lag free so there are some things you kind of just have to deal with, but until unet has better support and examples that don't have desync immediately on localhost, I'll be rolling my own solutions.

    My latest approach that was somewhat successful with unet was to have most of the game offline and singleplayer then later add in an object that interfaced with a server and received information for moving 'network dummies' that represented where other players were. I imagine this is more efficient than unity's solution of having the full class of each player for every machine and different logic based on whether or not that instance owns whichever player.

    It would appear that in my quest to reinvent the wheel, I'm coming up with less complicated solutions that are easier to use than unet. I believe that means it has failed as an attempt to be an easy introduction to networking :D
     
  49. zKici

    zKici

    Joined:
    Feb 12, 2014
    Posts:
    438
    Thanks for the quick response, do you have any trials / experience with Photon Bolt and/or Photon PUN+?

    If so would that be my best suited approach for this?
     
  50. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    All I can tell you about photon is that I haven't used it, but it needs a windows OS to run.

    Regarding networking in general - make small enough projects to grasp how the system works right now and then check on it frequently for updates. I can't really say much :p I had a few small projects and they were unsuccessful.