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

Showcase Mirror - Open Source Networking for Unity

Discussion in 'Multiplayer' started by mischa2k, Aug 11, 2016.

  1. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,341
    UNET is all about the low level api (LLAPI). That gets updates all the time - it just got multithreading a few weeks ago, which is huge.

    The HLAPI was meant as an example on how to use the LLAPI. Lots of people used that too. The HLAPI developer left Unity. Hence HLAPI was somewhat abandoned.

    UNET is still going strong though - LLAPI is what matters. And now we have some HLAPI fixes too anyway.
     
  2. Driiades

    Driiades

    Joined:
    Oct 27, 2015
    Posts:
    151
    HLAPI need to be good on RPC/Command, GameObject instanciation and SyncVar ( Things I don't use, It looks to be a huge gas factory ), for the rest ... It seems to be too games dependant :/ .
     
  3. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,341
    Why is it a gas factory? It's just a bunch of really useful abstractions.
     
  4. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,341
    Update: moved current experimental to stable; uploaded a new experimental version.
    • [2017-08-31] Removed unnecessary ChannelPacket class
      • Problem: ChannelPacket was only used by ChannelBuffer and it's pointless to reinvent the wheel
      • Solution: ChannelBuffer uses C#'s built-in MemoryStream now. Saves a lot of code and reduces probability of bugs.
    I researched the ChannelBuffer class and realized that the ChannelPacket class was kinda useless. It does save some allocations again, but the code complexity trade-off wasn't worth it in my opinion. Why reinvent the wheel.
     
    Last edited: Aug 31, 2017
  5. Che4Cuba

    Che4Cuba

    Joined:
    Jan 17, 2017
    Posts:
    31
    As Vis has displayed, Multiple scenes are possible and this mess, This HLAPI mess left over by Unity, Seemed to be a good reason to use UE as Unity couldn't handle the networking.
    Vis you have done exceptionally well and I'm glad that you have done something these guys couldn't.
    So consider this last part an open note to Unity, I would advise looking into this and paying this man for the work he has done for you, As he knows what he is doing and had done an amazing job fixing this.

    Using Unity 2017 (most recent) with HLAPI Pro Experimental and Networked Zones (multiple scenes, part of a verified UMMORPG version, no official release).

    I can now have a game with seamlessly perfect transition between scenes, because of Vis2k.
     
    camta005, Stormy102 and Deleted User like this.
  6. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    This looks really great, but the only thing that bothers me is that there is no "Zero GC Alloc" policy. I'd even say it's a dealbreaker for me. In general, when playing at acceptable framerates (100+ fps :D), it's still very easy to feel those GC spikes. I don't think even an improved garbage collector (if such a thing were to happen) would solve the problem

    However, since it really is fantastic work anyway, I think I just might start my own GC-less branch of it.

    But yeah, I think it's worth reconsidering if you intend this HLAPI to become the new standard. I've worked with several teams that wanted absolutely no runtime garbage in their game, and Playdead (creators of Inside) even made a Unite presentation on why they felt that they had to completely rid their project of any garbage. And then you've got Unity themselves who have that policy too. Zero-GC programming seems to be becoming kind-of a standard among Unity devs, and for good reasons
     
    Last edited: Sep 6, 2017
    Gekigengar, Stormy102 and Saishy like this.
  7. Xype

    Xype

    Joined:
    Apr 10, 2017
    Posts:
    339
    1 I think zero GC is a terrible term, it does not fit at all. it is not that there is no garbage to collect, it is that you are avoiding the terrible automatic collector and doing it yourself, assigning memory, managing it, destroying when it is no longer needed all with out the collector. If you screw up, you will wish you didn't bother. Make sure if you try to dev doing zgc methods that you exclude it from the editor, because when you hit play, and then stop it doesnt flush. The OS will only clear the assigned memory on application exit, and even then it is best to call a final collection on application exit just to be sure. Beyond that there is one big key thing you are missing, Unity isn't ready for it yet, I think its schedule for 2017.2? IL2CPP
     
    Gekigengar, xVergilx and camta005 like this.
  8. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    1,926
    You are right, I was just lazy with the terminology.
     
  9. Xype

    Xype

    Joined:
    Apr 10, 2017
    Posts:
    339
    All good, it seems to be crucial for VR from my understanding, not too worried for what I do. I just wanted to make sure someone else didn't read it and try to jump right in without the facts, it is a lot of work.
     
  10. surfknasen

    surfknasen

    Joined:
    May 8, 2017
    Posts:
    14
    When I try using NetworkManager.singleton.StopClient():
    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. UnityEngine.Networking.NetworkManager.ClientChangeScene (System.String newSceneName, Boolean forceReload)
    3. UnityEngine.Networking.NetworkManager.StopClient ()
    4. ExitToLobby+<ExitNumerator>c__Iterator0.MoveNext () (at Assets/_Scripts/ExitToLobby.cs:25)
    5. UnityEngine.SetupCoroutine.InvokeMoveNext (IEnumerator enumerator, IntPtr returnValueAddress) (at C:/buildslave/unity/build/Runtime/Export/Coroutines.cs:17)
    6.  
    I don't have this problem if I remove HLAPI Pro.
     
  11. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,341
    Any easy way for me to reproduce it?
     
  12. surfknasen

    surfknasen

    Joined:
    May 8, 2017
    Posts:
    14
    1. Create two scenes.
    2. In one of the scenes, create a network manager and a network manager HUD.
    3. Attach the scene with the network manager to "Online Scene" and the other one to "Offline Scene".
    4. Create a player prefab and put it on the "Player Prefab" on the network manager.
    5. Create a script that runs "NetworkManager.singleton.StopClient()" in Start() and attach it to the player prefab.
    6. Press play and host a LAN game.
     
  13. Vallar

    Vallar

    Joined:
    Oct 18, 2012
    Posts:
    177
    Hey @vis2k,

    I was wondering if there is an issue with HLAPI Pro when using the clientMoveCallback2D event/delegate/whatever on NetworkTransfrom. I tried using something like GetComponent<NetworkTransform>().clientMoveCallback2D but unfortunately it doesn't have that at all.

    Any idea what I might have been doing wrong? I even looked at the documentation and tried using it in a script inheriting from NetworkManager as it seems the case with the example in the documentation but it gave me the same exact issue.
     
  14. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,341
    Can you use the Script that you used? I tried it with this one:
    Code (CSharp):
    1. public class Test : NetworkBehaviour {
    2.  
    3.     // Use this for initialization
    4.     void Start () {
    5.         if (isClient) {
    6.             NetworkManager.singleton.StopClient();
    7.         }
    8.     }
    9. }
    And that works fine.

    The new NetworkTransform component has no more clientMoved callbacks because it uses interpolation and the client pretty much moves all the time.

    You can use a if (lastPosition != transform.position) check in your other script instead.
     
  15. Vallar

    Vallar

    Joined:
    Oct 18, 2012
    Posts:
    177
    Sorry for the stupid question, but is lastPosition being reported by the server/host? The reason I was asking about that callback is that I read somewhere that it is the method to make it act in a server authoritative manner as I am trying to avoid writing my own syncing for movement at the moment.
     
  16. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,341
    It works with client and server authority both by default, no need for any changes.
     
  17. Vallar

    Vallar

    Joined:
    Oct 18, 2012
    Posts:
    177
    Sorry for my ignorance but let me see if I understand you correctly:

    I create my own movement script let's say something in Update like this:

    Code (CSharp):
    1.  
    2. private void Update()
    3. {
    4. float x = Input.GetAxisRaw("Horizontal") * speed;
    5. float y = Input.GetAxisRaw("Vertical") * speed;
    6.  
    7. // rb = cached Rigidbody2D
    8. rb.MovePosition(rb.position.x + x, rb.position.y + y);
    9. }
    10.  
    Then attach a NetworkTransform to the player with "is Local Player" not ticked and neither the "is Server" on Network Identity and I am done?
     
  18. PrimeDerektive

    PrimeDerektive

    Joined:
    Dec 13, 2009
    Posts:
    3,090
    I’d really like to use this to fix the scene changing stuff but my project depends on NetworkTransformChild for VR hands and it looks like you removed it... is there any way to use HLAPI Pro but use the regular NetworkTransform/NetworkTransformChild? Can I just replace those files with in HLAPI Pro with the NetworkTransform/NetworkTransformChild source from unity’s Bitbucket before I drag it over?
     
  19. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,341
    You should read through the UNET manual to understand how this all works

    Yes, you could just use the old NetworkTransform.
    I can add TransformChild too later - I just didn't know that anyone needed that.
     
  20. PrimeDerektive

    PrimeDerektive

    Joined:
    Dec 13, 2009
    Posts:
    3,090
    Awesome, thanks! I’m on 5.6 btw, is it only compatible with 2017.1? I don’t mind upgrading, just wanted to check to see if I have to.
     
  21. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,341
    2017.1 yes
     
  22. Snownebula

    Snownebula

    Joined:
    Nov 29, 2013
    Posts:
    174
    Oh bs, I currently use it with 5.6 so its NOT only compatible with 2017.1.
     
  23. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,341
  24. PrimeDerektive

    PrimeDerektive

    Joined:
    Dec 13, 2009
    Posts:
    3,090
    Lol good to know, what an oddly aggressive response
     
  25. Snownebula

    Snownebula

    Joined:
    Nov 29, 2013
    Posts:
    174
    roar
     
    angusmf likes this.
  26. Vallar

    Vallar

    Joined:
    Oct 18, 2012
    Posts:
    177
    I already did. I guess what I am trying to ask is how in HLAPI Pro do you set NetworkTransform in a server authoritative manner. Not selecting isLocalPlayer in NetworkIdentity means that you end up with the player object not moving. Selecting that (from what I glean off what has been said) makes it that the NetworkTransform sends its position to the server and that opens the game for cheating, right?

    Side Note: Selecting Web Sockets in the NetworkManager doesn't allow clients to connect anymore when exporting to for testing. Can't recall if you mentioned it broke or not.
     
    Last edited: Sep 13, 2017
  27. marcV2g

    marcV2g

    Joined:
    Jan 11, 2016
    Posts:
    115
    Usually movement is client authoritative with the server checking if its moving faster than it should or out of bounds.
     
  28. Vallar

    Vallar

    Joined:
    Oct 18, 2012
    Posts:
    177
    Agreed but how do you check from the server? Does NetworkTransform do it automatically? If not, what do I do to do that check? lastPosition = transform.position that was suggested where should it be used? In a script that inherits from NetworkTransform? Should be put in the movement script with a reference to NetworkTransform and being checked every X amount of time?

    EDIT not to mention that NetworkTransform doesn't have a lastPosition field to check.
     
    Last edited: Sep 13, 2017
  29. marcV2g

    marcV2g

    Joined:
    Jan 11, 2016
    Posts:
    115
    I would add a separate component that checks and bans a player if the violation count gets too high.
     
  30. Driiades

    Driiades

    Joined:
    Oct 27, 2015
    Posts:
    151
    It's totally not the networkTransform to do that.

    Because it's gameplay logic. Some game allows teleportation or changes in the speed by items or whatever ....

    You need to work on a Anti-Cheat component only running on server.
     
  31. Vallar

    Vallar

    Joined:
    Oct 18, 2012
    Posts:
    177
    OK, correct me if I am wrong in this regard:

    NetworkTrasnform sends position from client to server. Server then applies movement. In this case, NetworkTransform is client authoritative -- from my understanding that is exactly what we have now.

    So to use server authoritative movement, what I would need to do is to create my own movement syncing logic and my own "anti-cheat".

    This is how I understand it so far.

    That said, I already have been working on my own server authoritative movement (with prediction and reconciliation but I am not sure it is good). I was hoping however that NetworkTransform would cut my work on that department and I simply use it in a server authoritative environment. It was said it was possible but I can't for the life me see how that is possible in the above scenario. Specially when there is no callback to use. It just doesn't fit since the position being reported from the NetworkTransfrom and the server applies without thinking.
     
  32. Driiades

    Driiades

    Joined:
    Oct 27, 2015
    Posts:
    151
    Normally client play their local movement and send to server.
    Server check if the movement is possible and send the positions to others clients.

    If not possible you have reconciliation. But I don't have implemented this, so I can't help you with this.
    http://www.gabrielgambetta.com/client-side-prediction-server-reconciliation.html a resource.
    the anti-cheat system is, I think, in the reconciliation.

    Prediction is just a super word to say : play the game locally haha.
     
  33. Vallar

    Vallar

    Joined:
    Oct 18, 2012
    Posts:
    177
    Yeah, I already have all this implemented without NetworkTransform as mentioned in my previous comment. I was just wondering if NetworkTransfrom can make it easier in implementing those systems and how it could do that.

    Thanks for the links though :)
     
  34. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,341
    NetworkTransform simply sends the player's position from the server to the clients. How you set that position is up to you - with a Cmd for example.
    Or you use local player authority, then NetworkTransform sends the position from the client to the server and the server broadcasts it to the other clients.
     
  35. Skjalg

    Skjalg

    Joined:
    May 25, 2009
    Posts:
    211
    Thank you for all your hard work vis2k. You're the hero we need :D
     
    mischa2k likes this.
  36. Vallar

    Vallar

    Joined:
    Oct 18, 2012
    Posts:
    177
    Aha!!! This is exactly what I was looking for! I didn't understand what is the component missing to get server authority with NetworkTransform and this makes sense.

    I tried exactly what you said and it worked. Though there is quite a delay between the input and the movement. I am guessing this is because it moves the server first without doing any prediction, am I correct?
     
  37. Driiades

    Driiades

    Joined:
    Oct 27, 2015
    Posts:
    151
    Code (CSharp):
    1.     public struct CommandMessage
    2.     {
    3.         public int cmdHash;
    4.         public string cmdName;
    5.         public byte[] payload;
    6.     }
    If you need to fix something; Maybe check if the HLAPI is really sending the full command name for a command call.

    Because the optimization will be great :s
     
  38. PrimeDerektive

    PrimeDerektive

    Joined:
    Dec 13, 2009
    Posts:
    3,090
    @vis2k agree, if you want to take a look at my thread here: https://forum.unity.com/threads/rid...n-commands-is-this-right.494842/#post-3219753 any insight or optimizations you can see to reduce my ridiculous 92 bytes of overhead per command, that would be great, because the unity employee basically just went ¯\_(ツ)_/¯
     
  39. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    He went ¯\_(ツ)_/¯ because it's not his field. He is the LLAPI developer. I am actually unsure who is the HLAPI dev atm.
     
  40. moco2k

    moco2k

    Joined:
    Apr 29, 2015
    Posts:
    294
    Yeah, I don't think that the UNET staff has provided any new information on their team setup since this post, right?
     
  41. PrimeDerektive

    PrimeDerektive

    Joined:
    Dec 13, 2009
    Posts:
    3,090
    I get that, but he's a Unity employee and represents a company, and there is no HLAPI guy. You know they have this beautifully designed page that is given prominent real estate on their website advertising a "core feature" of their product, with a huge calculator that will tell you the significant cost they're going to charge you to use this premium service?

    Oh, wait, that service is unoptimized, has a game-breaking scene changing bug, and no one on our team even works on it.
     
    xVergilx likes this.
  42. Driiades

    Driiades

    Joined:
    Oct 27, 2015
    Posts:
    151
    The tank demo doesn't work with me.

    Just attempting to connect to the game and.. fail.

    btw my project works great xD.
     
  43. surfknasen

    surfknasen

    Joined:
    May 8, 2017
    Posts:
    14
    I used that exactly, very confused why it's not working.
     
  44. Zullar

    Zullar

    Joined:
    May 21, 2013
    Posts:
    651
    SeanR was the only HLAPI dev I believe, but he left like 1.5yr ago or so? I believe Unity said they were bringing 2 devs onto the HLAPI once they were freed up (I think they said this like 6mo ago or so).
     
  45. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,341
    Correct. If you don't want the delay then you need client side prediction or a rubberbanding-like system.

    I only care about bugs + simpler code right now. As the saying goes: make it work, then make it fast.

    Scene changing should work with HLAPI Pro though

    Let's fix it ourselves then :)
     
  46. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,341
    Can you take a deeper look to maybe find the issue / try on another computer?
    My computers to test it on (and time) are greatly limited so any further investigating on your end would be very useful
     
  47. Xype

    Xype

    Joined:
    Apr 10, 2017
    Posts:
    339
    Oh they got something for you, you read through 2017.2 beta? They added 2 more channels that will handle larger sizes by segmentation hahaha. They don't care about your overhead, they just want to let it pass.
     
  48. Driiades

    Driiades

    Joined:
    Oct 27, 2015
    Posts:
    151
  49. surfknasen

    surfknasen

    Joined:
    May 8, 2017
    Posts:
    14
  50. Driiades

    Driiades

    Joined:
    Oct 27, 2015
    Posts:
    151
    On the Start(){} function. Called one and where isClient is in many time set to false.