Search Unity

  1. Engage, network and learn at Unite Austin 2017, Oct 3 - 5. Get your ticket today!
    Dismiss Notice
  2. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  3. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice
  4. Unity 2017.1 is now released.
    Dismiss Notice
  5. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice
  6. Unity 2017.2 beta is now available for download.
    Dismiss Notice

Unity Multiplayer UNET HLAPI Pro: taking UNET to the next Level!

Discussion in 'Multiplayer Networking' started by vis2k, Aug 11, 2016.

  1. Stormy102

    Stormy102

    Joined:
    Jan 17, 2014
    Posts:
    397
    These are prefabs stored in the assets. They already appear to have NetworkAssetIDs.
     
  2. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    1,775
    Update: uploaded a new experimental version. This one is very important:

    • [2017-08-25] Fixed Client Scene Switching/Loading
      • Problem: switching a scene would sometimes cause random object spawning errors and 'target not found' messages due to corrupted state.
      • Solution: I analyzed the Client<->Server handshake to find out at which point the client state got messed up. If the server sends a scene change message to the client, then there is no guarantee that this message arrives before the rest of the initialization (like object spawning). If the message arrives during initialization, then the scene will be loaded asynchronously and after the scene was loaded, all the state data like spawned objects are nulled. HLAPI Pro uses a new pausing mechanism that delays all message handling while a scene is loaded, making sure that all the spawning works perfectly fine even if spawn messages are received during a scene load.[​IMG]
     
  3. faviann_sauro

    faviann_sauro

    Joined:
    Sep 9, 2015
    Posts:
    5
    Yes I know but I was asking for HLAPI Pro. The HLAPI is under MIT/X11 but the MIT license allows for sublicensing and I did not want to assume that HLAPI Pro would fall under the same license and just throw in code contribution without asking.
     
  4. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    1,775
    Again sorry about the whole license thing. I just didn't have the time to deal with that yet, fixing the code seemed more important. I can't write those things myself since I am not a lawyer, so I'll have to go through all those existing licenses soon to find one that matches best.
     
  5. greeneninjagames

    greeneninjagames

    Joined:
    Mar 23, 2017
    Posts:
    4
    Cloud build is worthless if using this .dll right? I'm assuming so, but I wanted to ask in case there was a magic hax available to make it work.
     
  6. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    1,775
    Haven't tried it, but that would probably use the original HLAPI yes.
     
  7. amynox

    amynox

    Joined:
    Oct 23, 2016
    Posts:
    40
    @vis2k Great work and initiative !

    But... its seems to me that Unity is kind of abandoning UNET, we didn't hear any thing from them in the blog or there last events... No public roadmap, no communination... Maybe i'm miss-informed ?
     
  8. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    1,775
    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.
     
  9. Driiades

    Driiades

    Joined:
    Oct 27, 2015
    Posts:
    83
    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 :/ .
     
  10. vis2k

    vis2k

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

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    1,775
    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
    Wobes, Stormy102, nxrighthere and 2 others like this.
  12. yellinglionstudio

    yellinglionstudio

    Joined:
    Jan 17, 2017
    Posts:
    5
    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 Wobes like this.
  13. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    366
    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
    Stormy102 and Saishy like this.
  14. Xype

    Xype

    Joined:
    Apr 10, 2017
    Posts:
    138
    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
     
    VergilUa and camta005 like this.
  15. PhilSA

    PhilSA

    Joined:
    Jul 11, 2013
    Posts:
    366
    You are right, I was just lazy with the terminology.
     
  16. Xype

    Xype

    Joined:
    Apr 10, 2017
    Posts:
    138
    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.
     
  17. surfknasen

    surfknasen

    Joined:
    May 8, 2017
    Posts:
    6
    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.
     
  18. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    1,775
    Any easy way for me to reproduce it?
     
  19. surfknasen

    surfknasen

    Joined:
    May 8, 2017
    Posts:
    6
    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.
     
  20. Vallar

    Vallar

    Joined:
    Oct 18, 2012
    Posts:
    61
    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.
     
  21. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    1,775
    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.
     
  22. Vallar

    Vallar

    Joined:
    Oct 18, 2012
    Posts:
    61
    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.
     
  23. vis2k

    vis2k

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

    Vallar

    Joined:
    Oct 18, 2012
    Posts:
    61
    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?
     
  25. PrimeDerektive

    PrimeDerektive

    Joined:
    Dec 13, 2009
    Posts:
    3,036
    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?
     
  26. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    1,775
    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.
     
  27. PrimeDerektive

    PrimeDerektive

    Joined:
    Dec 13, 2009
    Posts:
    3,036
    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.
     
  28. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    1,775
    2017.1 yes
     
  29. Snownebula

    Snownebula

    Joined:
    Nov 29, 2013
    Posts:
    166
    Oh bs, I currently use it with 5.6 so its NOT only compatible with 2017.1.
     
  30. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    1,775
  31. PrimeDerektive

    PrimeDerektive

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

    Snownebula

    Joined:
    Nov 29, 2013
    Posts:
    166
    roar
     
  33. Vallar

    Vallar

    Joined:
    Oct 18, 2012
    Posts:
    61
    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
  34. marcV2g

    marcV2g

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

    Vallar

    Joined:
    Oct 18, 2012
    Posts:
    61
    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
  36. marcV2g

    marcV2g

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

    Driiades

    Joined:
    Oct 27, 2015
    Posts:
    83
    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.
     
  38. Vallar

    Vallar

    Joined:
    Oct 18, 2012
    Posts:
    61
    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.
     
  39. Driiades

    Driiades

    Joined:
    Oct 27, 2015
    Posts:
    83
    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.
     
  40. Vallar

    Vallar

    Joined:
    Oct 18, 2012
    Posts:
    61
    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 :)
     
  41. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    1,775
    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.
     
  42. Skjalg

    Skjalg

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

    Vallar

    Joined:
    Oct 18, 2012
    Posts:
    61
    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?
     
  44. Driiades

    Driiades

    Joined:
    Oct 27, 2015
    Posts:
    83
    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
     
  45. PrimeDerektive

    PrimeDerektive

    Joined:
    Dec 13, 2009
    Posts:
    3,036
    @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 ¯\_(ツ)_/¯
     
  46. TwoTen

    TwoTen

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

    moco2k

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

    PrimeDerektive

    Joined:
    Dec 13, 2009
    Posts:
    3,036
    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.
     
    VergilUa and nxrighthere like this.
  49. Driiades

    Driiades

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

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

    btw my project works great xD.
     
  50. surfknasen

    surfknasen

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