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,347
    I only support fixes-only until the UNET team decides what happens with HLAPI and until we know more about their future plans. I don't want to waste my time just to see this become obsolte a year from now.

    So for now we should focus on bug fixes here so that at least we can run our game servers without fear of critical bugs, etc.
     
    Arkade likes this.
  2. Arkade

    Arkade

    Joined:
    Oct 11, 2012
    Posts:
    654
    Oh. Oh dear. So not good prospects for UNet then?
     
  3. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    I don't know.
    There was this thread about giving HLAPI over to the community, but no more replies from the UNET team.
    There was the Multiplay acquisition for $20m, but nobody can talk about it.
    There was the GDC Keynote with the new Entity Component System and 'connected games', which they seem to be working on now. The ECS documentation has several notes about networking in there too.
     
  4. darthbator

    darthbator

    Joined:
    Jan 21, 2012
    Posts:
    169
    The acquisition that they made seems to be centered primarily on back end hosting technologies. The division of "Game" they purchased appears to be a DevOps heavy division that's focused on providing scalable services (instant servers, elastic databases, matchmaking) and not on the development of an actual API.
     
  5. PartyBoat

    PartyBoat

    Joined:
    Oct 21, 2012
    Posts:
    97
    That's the conclusion I came to as well. However, in this 2018 GDC talk that Joachim Ante (co-founder and CTO of Unity) just gave he says, "...We need to be great at networking, it just has to be true. We want to be the absolute best game engine for writing networked code."

    So who knows if that's just pure hype and Unity will drag their feet for years before we get anything (like the input manager), but if that's the stated goal then certainly the chief technical officer of Unity must realize that the HLAPI is nowhere near adequate in its current state. My bet is they are starting to work on something but we won't see it for a very long time.
     
  6. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Networking is mentioned in the ECS documentation several times, they are clearly working on this right now: https://github.com/Unity-Technologi...temSamples/blob/master/Documentation/index.md

    Joachim Ante is all about ECS and seems like he wants the new Networking to be specifially for ECS.

    That would explain the plan to hand over HLAPI to the community.
     
  7. S4UC1SS0N

    S4UC1SS0N

    Joined:
    May 29, 2014
    Posts:
    49
    I have a similar issue as raykatz, only the host transform is sync to the client.
    I downloaded only the two files for the NetworkTransform and replaced the default one by the pro one.

    (ps: i changed the needed types to make it compile)
     
    Last edited: Apr 4, 2018
  8. S4UC1SS0N

    S4UC1SS0N

    Joined:
    May 29, 2014
    Posts:
    49
    Ok my idea of just importing the NetworkTransform* script was not enough, the OnClientToServerSync message handler is not registered, instead it's the legacy one that handle the message and it fails to do so. I created a custom MsgType.LocalPlayerTransform and it fixed some of my issues, the player object now sync but not the others objects (with player authority).

    The problem come from NetworkTransformBase::Update, when this test happen :

    if (!isServer && hasAuthority && connectionToServer != null)

    "connectionToServer" is set only if the object is the player, so in the situation of an object with player authority (but not the player object), it's always null. And when this condition is false, nothing is sent to the server.

    Anyway, can anyone give me a link to download the compiled dlls ? I got errors when trying to compile them, i've never really built any csharp code outside Unity :$

    EDIT: ok i just realized Saishy already reported this bug last year, so i guess you forget about it ? ^^
     
    Last edited: Apr 6, 2018
  9. kophax

    kophax

    Joined:
    Jul 19, 2014
    Posts:
    20
    Hello.

    I'm currently using UNet in 2017.3 and I'm trying to get additive scene loading over the network working.

    I've got most things figured out / working, but right now my main problem is how sceneId on NetworkIdentity doesn't really care about additive scene loads.

    This results in colliding sceneIds for scene objects (network identities that are already in the scene at build time, not spawned after).

    I'm not seeing an easy solution here, have you done anything to address this with HLAPI Pro?

    Thanks!
     
  10. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Update: reverted NetworkTransform changes in HLAPI Pro fixes-only since too many people had issues with that. 2017.3 definitely works for Unity 2017.4 LTS by the way.

    Just redownload the DLL files from the first page.

    Enjoy!

    HLAPI wasn't designed with scene changes in mind. The HLAPI Pro workaround does work though. Additive scene changes might be... difficult.
     
  11. moco2k

    moco2k

    Joined:
    Apr 29, 2015
    Posts:
    294
    For my project, to avoid any synchronization issues that might happen when changing the online scene during a game in progress, I’ve come up with a solution which uses only one single online scene that is always active all the time of the game. Then, I ensure that all players, monsters, manager objects, and networked objects in general always belong to this scene. Any other needed game scenes are loaded additively with the SceneManager. Preplaced objects that need to be identifiable are assigned with unique, predefined ID's via editor scripts (btw these are not network instance id's, but they register themselves to managers and thus are accessible across network). Notably, I need to take care that all occlusion data is available in the online scene, because occlusion data cannot be loaded additively (sadly). It's definitely tricky and requires some additional design choices for respective systems, but the pattern works for me.
     
    Last edited: Apr 7, 2018
  12. kophax

    kophax

    Joined:
    Jul 19, 2014
    Posts:
    20
    Interesting moco2k, thanks for the info.

    From what I was reading it seems like occlusion data may now be supported (since 5.5?) but you need to have occlusion data baked for your original scene before the load?

    https://forum.unity.com/threads/loading-occlusion-culling-additively-in-unity-5-5.449203/\

    Though reading deeper, maybe you have to bake it in a certain way:

    https://docs.unity3d.com/Manual/MultiSceneEditing.html

    Can you confirm or deny this?
     
  13. moco2k

    moco2k

    Joined:
    Apr 29, 2015
    Posts:
    294
    To my knowledge, occlusion data still cannot be loaded/unloaded additively. However, while in editor, you can additively load all of the scenes that you will need for your project and then bake everything into a single occlusion data file. As a result, you will have one big dataset that is linked to the active scene. Later on, during runtime, you can load and unload particular scenes and the big occlusion data will work for them.
     
    Last edited: Apr 8, 2018
  14. Miscellaneous

    Miscellaneous

    Joined:
    Sep 24, 2013
    Posts:
    53
  15. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    I am still here and still focusing on bugfixes-only for HLAPI Pro until we know more about that HLAPI community takeover that the UNET team talked about.
     
    Siedgex and LiterallyJeff like this.
  16. Siedgex

    Siedgex

    Joined:
    Sep 15, 2015
    Posts:
    1
    Just came across this today, thank you so much for doing this!
     
    mischa2k likes this.
  17. PrimeDerektive

    PrimeDerektive

    Joined:
    Dec 13, 2009
    Posts:
    3,090
    Hey Vis, I had a question about NetworkAnimator... I have some AI NPC's that are scene objects with server authority, but when I add the NetworkAnimator to them outgoing bytes on clients increases by 1000-1500 per second. I had this issue with built-in HLAPI too obviously, looked at your NetworkAnimator improvements (specifically the sendMessagesAllowed stuff you added) and it looks like it should fix it, but I installed HLAPI Pro with improvements and the same issue is happening. I've tried toggling local player authority both off and on on said NPC's with the same result.

    Edit: my mistake, I was looking at an older version of Unity's official bitbucket repo for UNET, looks like they added that sendMessagesAllowed stuff themselves in 2017.1. Still, its a headscratcher :(
     
    Last edited: Apr 19, 2018
  18. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    I never use NetworkAnimator in any of my projects. I recommend having a simple state like IDLE/WALKING/JUMPING, syncing that over the network and passing it to the animator locally. This works really well in uMMORPG etc.
     
  19. PrimeDerektive

    PrimeDerektive

    Joined:
    Dec 13, 2009
    Posts:
    3,090
    Yeah, that's what I'm currently doing with syncvar bools, but I mean, that's essentially what the NetworkAnimator is supposed to do by autopopulating a really user friendly inspector for selecting which parameters you want to sync. If I have different AI units that have different animator parameters I'll have to create unique custom network animator scripts just to create different syncvars for the unique parameters. If the NetworkAnimator worked properly it'd be a really nice workflow.
     
  20. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Agreed
     
  21. brubcruz

    brubcruz

    Joined:
    Feb 13, 2018
    Posts:
    3
    So "HLAPI_Pro_fixesonly_Unity_2017.3.zip" uses the old NetworkTransform correct?
    After replacing the DLLs it kept the same in the editor.
    It is working on the game while playing, but in the editor, when an object with networktransform is selected, throws an exception:

    NullReferenceException: Object reference not set to an instance of an object
    UnityEditor.Networking.NetworkTransformPreview.OnPreviewGUI (Rect r, UnityEngine.GUIStyle background)

    Unity version 2017.3.
     

    Attached Files:

  22. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Uses original HLAPI NetworkTransform yes.
    I think that error is normal. I get it too sometimes, probably a Unity bug? Doesn't show a stack trace related to HLAPI Pro either.
     
  23. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    In case someone missed it: Unity 2018.1 news https://unity3d.com/unity/whats-new/unity-2018.1.0
    • Multiplayer: You can now set Unity up to send you notifications about defined callbacks when there is something to read or the connection is ready to send information.
    • Multiplayer: Two or more channels can now share the messages order, so that messages which send via differnet channels are delivered in order.
    • Multiplayer: Added GetHostPort function, reporting the port number assigned to the host.
    • Multiplayer: Deprecated unused function NetworkTransport.GetAssetId(). (950325)
    • Multiplayer: Fixed issue with scene id determinism during scene post processing. (935230)
    #950325 and #935230 were both reported by me. Didn't anyone else report anything?

    Btw @larus @aabramychev thanks for the improvements! Could you please update 2017.4 and 2018.1 HLAPI sources on Bitbucket?
     
  24. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    Just wanted to throw a suggestion your way about SyncedVars. I know you know send a ulong to get 64 SyncedVars, but here is how I solved it in the MLAPI.

    Instead of treating the state as a uint. Treat it as a bool array. You are guaranteed to have the same amount of SyncedVars on the sending and receiving end. Thus you can write x amount of bools as bits. This means that if you only have 1 SyncedVar, you only have 1 bit of overhead (or one byte if you use a binary writer). This removes the limit and allows for unlimited SyncedVars but also saves bandwidth by not sending a fixed size. With that you will always get the same or better performance (bandwidth wise) while not having a fixed limit.
     
    mischa2k likes this.
  25. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Agreed.
    UNETWeaver uses Mono.Cecil to do a lot of crazy stuff with SyncVars that will all have to be modified to work with byte arrays. Don't really want to deal with that atm, especially to guarantee easy updates / compatibility with default HLAPI.
     
  26. antsonthetree

    antsonthetree

    Joined:
    May 15, 2015
    Posts:
    102
    Hello - I notice that 2017.4 Fixes Only source is not available on your bitbucket. Can you please update that?
     
  27. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    We don't have 2017.4 or 2018 original HLAPI source code, UNET team didn't upload that.
    2017.3 works with 2017.4 for now though.
    2018 only has 1 bug fix, which I already fixed in HLAPI Pro anyway.
     
  28. FlyingHighUp

    FlyingHighUp

    Joined:
    Apr 23, 2012
    Posts:
    16
    Last edited: May 7, 2018
  29. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Will update soon. Just took a quick look, the sceneId bug is the only interesting part. Looks like the UNET team tried to use my fix (you are welcome btw), but they did it wrong. Still not fixed.
     
    Last edited: May 7, 2018
    Driiade and TheBrizleOne like this.
  30. Peschken

    Peschken

    Joined:
    Jul 29, 2017
    Posts:
    7
    Heya, I'm currently experiencing an issue when changing scenes using ServerChangeScene. When using this to go from my main menu to the first level where the players get spawned, it works fine. But when I try to restart the level by changing to the same scene upon death, I get this error: NullReferenceException: Object reference not set to an instance of an object UnityEngine.Networking.ClientScene.OnObjectSpawnFinished (UnityEngine.Networking.NetworkMessage netMsg)
    But I am never calling that function anywhere, so I have no idea where it comes from. I have this in the regular HLAPI and it remains when I installed HLAPI Pro. Thanks in advance!
     
  31. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Don't switch scenes unless you absolutely have to (e.g. network zones etc.).
    UNET has scene switching, but it's awful. HLAPI Pro makes it barely work.

    You could try to report this bug to Unity though.
     
  32. Peschken

    Peschken

    Joined:
    Jul 29, 2017
    Posts:
    7
    Thank you for the answer, But I really do need to switch scenes. I am now getting that error as well when just switching from my main menu. I have no idea of what I could do... I might give up on multiplayer. Thank you anyway
     
  33. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Might be worth trying to debug HLAPI if you have a day of time
     
  34. Peschken

    Peschken

    Joined:
    Jul 29, 2017
    Posts:
    7
    I'd love to, but I don't believe I have the knowledge to do that.
     
  35. ws04100236

    ws04100236

    Joined:
    Jan 20, 2015
    Posts:
    2
    My version is Unity 2017.3 1f1. When I build UWP application with HLAPI Pro, there will be a lot of unet.

    The Reference rewriter: Error: method ` System. UInt64 UnityEngine.Networking.Net workBehaviour

    A similar error, and then I can switch back to HLAPI to be normal.I needed it, but I was overwhelmed by the packaging.
     
  36. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    I am not on Windows myself, can you post the whole stack trace please?
     
  37. ws04100236

    ws04100236

    Joined:
    Jan 20, 2015
    Posts:
    2
    Of course, I'm developing a multi-player collaboration based on uNet and a third-person Hololens application, and here's the error stack thrown at build: uwp build error image.png
    More information on text.
     

    Attached Files:

  38. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    That's odd. I am not sure why the SetSyncvar with 32 bits would exist in the target framework.
    Sounds like the Unity guys added some UNET code to whatever target framework that is.
    I suppose there's nothing we can do unless they open source that part too. It really would be better if we could just drop the HLAPI source into our Unity projects and then build from there. Right now we replace 4 DLL files - but if there's another one that they didn't tell us about, then these things will happen.

    Feel free to ask the UNET team if you want.
     
  39. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Update: 2018.1 added, see first post.

    Enjoy!
     
    TheBrizleOne likes this.
  40. nickonmir

    nickonmir

    Joined:
    Feb 10, 2018
    Posts:
    2
    So I'm using the 2018.1, but it seems as though NetworkTransform is broken? If a Rigidbody is added to the object along with NetworkTransform, then the NetworkTransform insists that it can't find a Rigidbody despite it clearly being on the object. This error appears no matter what settings the NetworkTransform has, even when it shouldn't involve a Rigidbody. If the Rigidbody isn't added to the object at all, then everything is fine. The error also pops up in the editor, without running. Theres a statement saying to add a Rigidbody reference in the inspector for NetworkTransform, but that slot doesnt exist.

    MissingComponentException: There is no 'Rigidbody2D' attached to the "PlayerCharacter(Clone)" game object, but a script is trying to access it.
    You probably need to add a Rigidbody2D to the game object "PlayerCharacter(Clone)". Or your script needs to check if the component is attached before using it.
     
    Last edited: May 28, 2018
  41. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Which HLAPI Pro version?
     
  42. nickonmir

    nickonmir

    Joined:
    Feb 10, 2018
    Posts:
    2
    2018.1.0f2 on unity. This seems to be more of an issue if spawning the object with the Rigidbody and NetworkTransform through code, rather than the NetworkManager spawner. For example, using NetworkServer.Spawn(), from the prefab spawned by the Network Manager, to spawn the actual player controller.
     
  43. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Probably happens in the original HLAPI too then?
     
  44. Severos

    Severos

    Joined:
    Oct 2, 2015
    Posts:
    181
    I'm planning on writing some network game again using Unity and happen to come across this. Just want to make sure of one thing before starting, this HLAPI Pro have same API and workflow of the "original" HLAPI ? like I won't need to lookup any extra study materials??
     
  45. martaaay

    martaaay

    Joined:
    Apr 13, 2009
    Posts:
    136
    Hi @vis2k , I'm getting a spew of these errors I think after an ios app is backgrounded for a while (even in offline mode). I'm having trouble reproducing this consistently just yet.

    host id {0} invoked wrong io operation and will be deleted
    host id {0} out of bound or host has been already removed
    host id {0} invoked wrong io operation and will be deleted
    host id {0} out of bound or host has been already removed
    ...

    Do you know if this is coming from HLAPI Pro? I'm not seeing it in Unity's networking source and can't seem to find much on it just yet.

    Thanks!
     
  46. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Exactly the same, you can replace it and go back to HLAPI if needed any time.

    Might be LLAPI too. I recommend reporting it to Unity.
     
  47. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    News: created a new HLAPI Pro repository from scratch, this time with branches for different Unity versions (see first post).

    This allows me to apply improvements to just one set of files and then build 2018.1 etc. versions from them without reapplying all the improvements.

    In other words: behind the scenes progress for now, more real progress soon.
     
  48. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Update: NetworkWriter.Position type changed from 'short' to 'int' to fix a bug where writing >32kb into NetworkWriter would result in negative .Position
     
    TheBrizleOne and goldbug like this.
  49. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Update: fixed a bug where one of the most important settings in NetworkManager was completely ignored by HLAPI:
    upload_2018-6-8_16-46-47.png

    Everyone's projects still used max buffered packets = 16. What the hell.
     
    TheBrizleOne, Hitch42 and goldbug like this.
  50. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Update: added a new Improvements branch basedon 2017.4, DLLs can be found in the first post. Will only be based on 2017.4 LTS for now. Changelog can be seen on the repo: https://bitbucket.org/vis2k/hlapi-pro/branch/Improvements

    It's less intrusive than last time (public variables weren't touched, etc.). The main goal is to simplify HLAPI where possible to end up with something that's hopefully a lot more stable.

    It's just a branch this time, so I can continue to apply only bugfixes to master and then rebranch the improvements based on that any time.

    I may have posted this before, but here is one of the best examples on why improvements are badly necessary.
    Before:


    After:
     
    goldbug and GoDJaMMing like this.