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. Artaani

    Artaani

    Joined:
    Aug 5, 2012
    Posts:
    423
    No matter how this error is called.
    From the point of view of new user who are trying to create multiplayer game first time using this "brand new UNET which is out of beta" - it is extremely confusing, because in all other cases, if there is red error in the console after a compilation - it will be in the console until problem will be solved.
     
  2. angusmf

    angusmf

    Joined:
    Jan 19, 2015
    Posts:
    261
    Let me put this another way. The bug isn't really about OnStartAuthority. It's about the fact that hasAuthority never has the correct value except for the one client that actually has authority. ALL the clients will return has Authority == true, even though (obviously) only one or none of them have it.

    ---edit---
    sorry, I gave up caffeine in the mornings. hasAuthority has the incorrect value on the server, not clients.
     
    Last edited: Nov 17, 2017
    nxrighthere likes this.
  3. MCoburn

    MCoburn

    Joined:
    Feb 27, 2014
    Posts:
    71
    I had thought that better multitasking was achieved through high caffeine intake, but I guess I was wrong.

    Can you please confirm @vis2k that you got my message with the project archive from Discord?
     
  4. rob_vld

    rob_vld

    Joined:
    Jul 9, 2013
    Posts:
    190
    When connecting too many clients to fast the server no longer allows new connections... then after a while it allows them again... how do i change the delay on this?
     
  5. MCoburn

    MCoburn

    Joined:
    Feb 27, 2014
    Posts:
    71
    @rob_vld Sounds like that is some sort of flood protection built into the UNET stack. What error gets returned? A specific message when the protection is active?
     
  6. rob_vld

    rob_vld

    Joined:
    Jul 9, 2013
    Posts:
    190
    Looks like it...

    Only the client throws an error, that it timed out.
    The server is still fully operational with connected clients but does not output any connection/error messages
     
  7. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Yes but I wasn't able to extract it for some reason. Maybe just post the scripts in here?
     
  8. MCoburn

    MCoburn

    Joined:
    Feb 27, 2014
    Posts:
    71
    I compressed it using 7Zip with maximum LZMA2 compression so you might have been using some older archiving software. I'll post the scripts and how to set it up to replicate it.
     
  9. MCoburn

    MCoburn

    Joined:
    Feb 27, 2014
    Posts:
    71
    Here's the steps as requested; otherwise you can download the project for 2017.2 from this link (it's the same archive but I converted it from 7Zip to Zip archive file format). Just extract, open it up (inspect it first if you're security paranoid, there's no hidden nastiness) and build. Probably the most time effective way.
    • Create a new blank project using Unity 2017.2. Don't import anything.
    • Save the empty scene that is given to you on startup of Unity.
    • Save this scene as "boot". Add to build settings.
    • Make a new game object called Network. Add this script (DebugNetManager.cs) to it.
    • Ensure that the channels are Reliable and Unreliable. Set "Run in background" to true. Set logging level to Debug/Developer.
    • Make a new game object called Startup. Add this script (Connector.cs) to it. Drag the Network gameobject to the slot on the script that says "NetMan".
    • Make a prefab called PlayerObject. I used a capsule. Attach a NetworkIdentity, NetworkTransform and this script (VerySimpleController.cs) to it. Set it as local player authority on the network identity. Save this prefab and assign it to the DebugNetManager's player prefab slot.
    • Optionally, I added a UI text to know what button did what (I'm forgetful like that) saying "1 = Server, 2 = Client"
    • Save the scene. Close scene and create new scene. Save as "network" and add to build settings as level 1.
    • Add a plane as the floor and give it a networkidentity.
    • Save. Close that scene and open the "boot" scene.
    • Build a standalone player and run it. Ensure it has "Development Build".
    • Press start on the editor. Press 1 to start the server; ensure that your prefab spawns and you can use the arrow keys to move it by one 1 unit around in 4 directions.
    • On the standalone player, press 2 to connect to the editor instance and start the client.
    • The client should record in the log "Client Scene change: network" and throw a error saying "A connection is already marked as ready, there can only be one."
    • If you get that, success! You've replicated the bug.
     
  10. lucasmontec

    lucasmontec

    Joined:
    Apr 7, 2015
    Posts:
    97
    Is it okay for me to use this in my commercial project? Since this has no license I've been avoiding its use so far... But I really want to use most of the fixes here. The problem is: my budget for this project I'm working is 0 USD. If the license changes, I'd have to remove this library and fix all the issues my self (I already fixed some of them tho).
     
  11. MCoburn

    MCoburn

    Joined:
    Feb 27, 2014
    Posts:
    71
    I think vis2k has already stated that you can use it in a commercial project, but just realize it is still a work in progress. It is already used in conjunction with his own assets.
     
    lucasmontec likes this.
  12. lucasmontec

    lucasmontec

    Joined:
    Apr 7, 2015
    Posts:
    97
    Unet itself is a work in progress XD. I'm just asking to confirm that the license wont be something like GPL, or suddenly a paid license with all rights held.
     
  13. MCoburn

    MCoburn

    Joined:
    Feb 27, 2014
    Posts:
    71
    I'm not sure if vis2k could do that to be honest. I'm not a lawyer nor do I know what the original license is.
     
  14. MCoburn

    MCoburn

    Joined:
    Feb 27, 2014
    Posts:
    71
    Alright, so after analyzing the code with the double ready, I was able to get it to no longer throw the double ready. This is my fixed OnClientSceneChanged() function:

    Code (CSharp):
    1.     public override void OnClientSceneChanged(NetworkConnection conn) {
    2.         print ("Client scene change: " + networkSceneName);
    3.  
    4.         if (conn.isReady == false) {
    5.             Debug.LogError("We're not ready. So we'll become ready.");
    6.             ClientScene.Ready(conn);
    7.         }
    8.  
    9.         if (autoCreatePlayer)
    10.         {
    11.             // add player if all existing ones are null (or if list is empty, then .All returns true)
    12.             if (ClientScene.localPlayers.All(pc => pc.gameObject == null))
    13.             {
    14.                 Debug.LogError("Adding a player object because all existing ones are null.");
    15.                 ClientScene.AddPlayer(0);
    16.             }
    17.         }
    18.     }
    On the server, it throws two fake errors, being the ones that I just put in that code - "We're not ready" and "Adding a player object". On the client, we're just checking if our connection is already in the ready state, and if not, then we ready up.

    Apparently it works for my little HLAPI network debugging project (which is available in the posts above).
     
  15. lucasmontec

    lucasmontec

    Joined:
    Apr 7, 2015
    Posts:
    97
    There is no license in the project yet... no license by default is full copyright to the owner.
     
  16. Drannach

    Drannach

    Joined:
    Apr 6, 2014
    Posts:
    25
    Hello vis2k, i just installed HLAPI pro to use it with ummorpg but now i get this error with the Third person controller from Opsive :

    HLAPI pro vs third person controller Unity 2017.2.0f3.jpg

    I'm probably missing something...?

    Thanks!
     
  17. MCoburn

    MCoburn

    Joined:
    Feb 27, 2014
    Posts:
    71
    Check the bit bucket repo, there is a license file there...?

    Comment out the lines in that source code file that reference the missing property as you just want to make it so it only does a AddComponent<NetworkTransform>() call.

    I detailed the process here in this thread.

    (PS: I help with support over at the Opsive Forums. I've got a thread there with this HLAPI Pro thing, best to report such things there).
     
    Last edited: Nov 24, 2017
    mischa2k likes this.
  18. Drannach

    Drannach

    Joined:
    Apr 6, 2014
    Posts:
    25
    Thanks a lot, i missed it...
     
  19. lucasmontec

    lucasmontec

    Joined:
    Apr 7, 2015
    Posts:
    97
    as I said:
    "
    HLAPI Pro License:
    This is a preview for testing purposes only.
    All rights reserved.
    -> Do not copy/fork/redistribute etc. until I come up with a proper license."

    This is no license. Not one that I can consider 'usable' or 'safe'.
     
  20. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Sorry for the late reply, been busy with the black friday sale.

    I looked at your project. Here is what happens:
    • OnClientConnectInternal is called and since string.IsNullOrEmpty(m_OnlineScene) is true, it sets clientLoadedScene=false
    • OnClientConnect then sets Ready because clientLoadedScene is false
    • OnClientSceneChanged later sets Ready too
    So..
    • This is a UNET bug as far as I can tell - you would see it in the original HLAPI too if it would properly load scenes without bugs
    • It mostly happens because UNET expects online scene and offline scene both to be set as far as I can tell. In your code you only set offlineScene in ConnectToServer. If you set both online and offline scene at all times then it works (you can also just drag them into the NetworkManager's slots)
    So in other words, always set both scenes to avoid these issues. UNET should either tell you to always set both scenes, or properly work with just one scene being set. The lack of comments in the HLAPI code makes this a bit difficult to say for sure, I can only speculate and if I force either of the two options then something might break otherwise - since I have no idea why the author decided to (for example) only check string.IsNullOrEmpty(m_OnlineScene).

    Hope that helps.

    I will try to find a proper license by the end of the year or by the time when someone absolutely needs to release their game - which ever happens first.

    To elaborate, I try to make the right decision to guarantee a stable UNET for the next 5 years so you guys and myself can release our games without going mad.

    If I just go with something like MIT license and make it 100% free, then that's great except for the fact that it doesn't pay the bills and I won't be able to spend large amounts of time on it. That's kinda what the HLAPI needs right now though, to iron out all the issues. There is a LOT of work to do. Hence the other option, making it 'pay what you want' or 'pay for commercial use' etc. so that I can spend a lot more time on it.

    Perhaps the best thing to do is a bugfixes-only HLAPI Pro and wait to see what the UNET developers invest into it themselves during the next year. And if it still isn't any better one year later, then maybe it's time to really rewrite large parts of it.

    I am not sure yet, open to suggestions..
     
    Last edited: Nov 24, 2017
  21. MCoburn

    MCoburn

    Joined:
    Feb 27, 2014
    Posts:
    71
    I completely understand that if you pour time and effort into improving/bugfixing a existing API that you should be compensated in one form or another. As long as the pricing is reasonable (I'd say $10 - $25 p/mth, nothing super expensive), I would be willing to purchase a support contract/license/thing to ensure that I get support for a key item in my project's networking stack.

    I am planning to release an alpha demo of my game probably Q1 2018 so unless you mean we need to sort out the license if it was for a full game, we might need to review the licensing.
    -------------
    In regards to scene switching and the ready bug, if I was to make a empty scene and use that as the online scene, would the client automatically switch to the correct scene when it connects to the server? Or will setting an online scene force UNET to use that scene as the one to do all the communication until the server instructs a scene change?

    I assume that it would be like the following after setting offline/online scenes:
    1. Client starts
    2. Client immediately switches to online scene
    3. Client connects to the server, checks networkSceneName
    4. networkSceneName is different - change to same scene as server
    5. Sync up
    6. Server <-> Client communication is active
    The current setup as you saw in the project doesn't set the online scene as I had the impression that if you're connecting to a server/host, you won't know what scene is on that instance. Originally, to work around this I had implemented a socket server that listened and responded to get network scene names, allowing the client to switch to that scene and then start the client - before I came across HLAPI Pro, but that led to all sorts of complications.
     
    Last edited: Nov 25, 2017
  22. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Set an online and offline scene and ideally never change them afterwards.
    Also I wouldn't use a loading scene, that's probably not worth the trouble that you will run into.
     
  23. MCoburn

    MCoburn

    Joined:
    Feb 27, 2014
    Posts:
    71
    Apparently I didn't see your reply before I edited my post. (Bugger.)

    Anyway, I'll throw what I had as a question here just for completion sake.
    Say for example I had the offline scene as the main menu, and the online scene as a empty saved scene (ie. a camera and no geometry). When the client starts I assume it immediately will load the online scene, then once it connects, it will load the network scene that the server is on. Am I correct?

    The reason I ask this is because the server might be on a scene named "mp_testlevel" while the client is still on the empty saved scene, let's say "mp_bootup_blank". I assume the UNET Client will realize that the networkSceneName between the server and client is different and the client will immediately change scenes.
     
  24. MCoburn

    MCoburn

    Joined:
    Feb 27, 2014
    Posts:
    71
    Alright, so to test my theory:

    I set up a blank scene as the network online scene. So "boot" is the offline, "prelude" is the one that should be loaded as soon as the server comes up, and "network" is the one that should be switched to.

    Server starts up and loads scene "prelude". It should go to the "network" scene.

    In my code I then have this:

    Code (CSharp):
    1.     public override void OnStartServer () {      
    2.         print("Switching scenes now.");
    3.         ServerChangeScene("network");
    4.     }
    Turns out that the scene changes to the one called "network" but then the server finishes initialization, it switches back to "prelude" which is the one that is set in the NetworkManager slot. Visualizing this, the order of loading go is boot -> network -> prelude instead of boot -> prelude -> network.

    So I had to make a little check in LateUpdate() - which is definitely not the best solution - so when the server is settled, it switches scenes to "network". Clients when they connect throw the "We're not ready. So we'll become ready" fake error from my posts above so I know they have connected okay.

    I'm going to have to work around this for my shooter project as I plan to have multiple individual maps playable over the network, I need the server to load the scene with them in it as well as the client. I understand that in an MMO, you'd have one big world scene that contains everything (or multiple scenes stitched together with LoadLevelAsync).

    I swear UNET has some really weird design choices.
     
  25. Vallar

    Vallar

    Joined:
    Oct 18, 2012
    Posts:
    177
    Hey @vis2k any chance that HLAPI Pro would work with WebGL export like normal HLAPI or perhaps any work around that we can do from our end to make it work?
     
  26. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    I don't see why wouldn't work - did you try it?
     
  27. Vallar

    Vallar

    Joined:
    Oct 18, 2012
    Posts:
    177
    Yes of course, if I turn Use Websockets on in the Network Manager the client never connects to the server no matter how long I wait. When I turn it off, it connects normally. Normal UNET works well.
     
  28. RajulG

    RajulG

    Joined:
    Jan 2, 2017
    Posts:
    3
    @vis2k , Thanks for all the effort for this !
    I wanted to ask if

    • [SyncVar(bool owner)] works for only for local player objects , or does it even work for player authorized objects ( spawned from server ) ?
    • Also in original NetworkTransform, if we have a player authorized object and we control its movement from the server, it updates it position to all other players besides the player who owns it, does it happens in this or you changed that ?
    Thanks again !

    EDIT :- After adding this, the non server player is not able to move his authorized object ( the objects spawned from server but authorized to a player ) ? server is able to move his and its own ..., do i have to change anything ?
     
    Last edited: Nov 28, 2017
  29. lucasmontec

    lucasmontec

    Joined:
    Apr 7, 2015
    Posts:
    97
    Hey @vis2k I completely understand that... The only problem for me and my team is that we currently run on a 0 USD budget. I would gladly pay if I could, but I can't. Brazil isn't the best place to be a game developer... Still, I'd suggest you go with something like royalties, but more like unreal or unity do. If we make more than X, you get Y%. Or, if we make more than X per year, we need license Y (that costs per month, or has a fixed cost). This way we can use the full library and pay you when we succeed in our endeavours. What do you think?
     
  30. chiapet1021

    chiapet1021

    Joined:
    Jun 5, 2013
    Posts:
    605
    With respect, I'm generally not a fan of revenue-based license models or stratification. In principle, it's nice for a developer in that they only pay if they are successful. But enforcing that type of license requires that developers honestly and regularly disclose their revenue to the licensor and for the licensor to have some mechanism to verify those disclosures. It's operational overhead on both sides, with more of that burden on the licensor.

    That model works better for big companies like Unity and Epic (for UE4). It seems infeasible for a single developer shop.
     
    MCoburn and lucasmontec like this.
  31. MCoburn

    MCoburn

    Joined:
    Feb 27, 2014
    Posts:
    71
    I agree with this point of view but I personally would think a one-time purchase would also be feasible. Then people would be able to justify the purchase with a "Well, the built-in Unity HLAPI is S***; this one is pretty much a drop-in replacement with major improvements and less redundancy" reasoning. Many assets out there currently do the one-time purchase model and it'll allow others to say "Oh for x dollars you can get HLAPI Pro and it's great, it's an improved drop-in replacement for stock UNET". Maybe charge a 10%-off upgrade price when you hit a major version (ie. HLAPI Pro 2.0) so you get people coming back.

    Back that up with solid support and I reckon you'd be a winner.
     
    chiapet1021 and mischa2k like this.
  32. shamsfk

    shamsfk

    Joined:
    Nov 21, 2014
    Posts:
    307
    I would gladly pay for HLAPI Pro some justifiable one-time payment (no % bullshit, I would use UE instead of Unity if not % payments as I had years of experience with it, and monetization policy was the sole reason to move) with major version upgrade price once a year. If it would leave its source open, as there were made some controversial decisions like using MemoryStream, as garbage on a Unity-based MMO server is the worst enemy it should be changeable to justify using HLAPI Pro on a long-running server.

    P.S. We were in the process of making our own HLAPI fork when HLAPI Pro came to my attention, so we stopped the process to see how HLAPI Pro will do, I hope vis2k will decide with the license soon enough. It kinda needs to be known now.
     
    Last edited: Nov 30, 2017
  33. David-Kimball

    David-Kimball

    Joined:
    Sep 18, 2014
    Posts:
    8
    @nxrighthere how do I go about "writing all the code manually" to fix this issue? Things were working fine and then a fresh project -> uMMMORPG and I get this error during build. How do I clean it up if writing the code is a more involved option? Thanks!!!
    Type '[Assembly-CSharp]UnityEngine.Networking.NetworkManager' has an extra field 'clientLoadedScene' of type 'System.Boolean' in the player and thus can't be serialized (expected 'isNetworkActive' of type 'System.Boolean')
    UnityEditor.BuildPlayerWindow:BuildPlayerAndRun()
     
  34. MCoburn

    MCoburn

    Joined:
    Feb 27, 2014
    Posts:
    71
    How feasible would it be to implement a sort of build number system? For example, for a shooter, you might be on v1.00 but the dedicated server is on v1.02. You do not want clients that are v1.00 connecting to a v1.02 instance, as some stuff may have been changed, etc. I'm not sure if ScriptCRCMismatch does this rendering my question invalid.

    Of course, I would implement some sort of version check before you actually can get into Multiplayer parts of the game. This is just if they workaround that check system.

    Even if it's a integer that is checked between the server and client on connection, if mismatch is detected, disconnect and throw an error saying build version mismatch.
     
    Sarrivin likes this.
  35. Vallar

    Vallar

    Joined:
    Oct 18, 2012
    Posts:
    177
    @vis2k Any updates on the WebGL issue? I tried again with an empty project and it didn't work.

    1- Created empty game object. Threw default NetworkManager on it.
    2- Enabled Use WebSockets.
    3- Created another empty game object as player. Dragged prefab to NetworkManager.
    4- Launched Server Only in Editor.
    5- Launched exported game as Client. No connection says Timeout.
    6- Go back to editor increase timeout values.
    7- Save and export, launch the exported game as Server Only. Try to connect with Client, same error with Timeout and never connects.
    8- Turn off Use WebScockets, it works fine.
     
    Edan-Smith likes this.
  36. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Sorry, not sure if I asked you that before but: does it happen with default HLAPI too?
     
  37. Vallar

    Vallar

    Joined:
    Oct 18, 2012
    Posts:
    177
    You did and after I answered I double checked. 5.6.0f3 has the problem, 5.6.3f3 doesn't have the problem. 2017.1.1f3 has the problem, 2017.1.2p3 has the problem.

    Using HLAPI Pro on 5.6.3f3 (which default Unity Use WebSockets works in) produces the problem.
     
    Edan-Smith likes this.
  38. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    I see. I will try and release a bugfixes-only HLAPI Pro version without all the refactoring and then we will see what happens.

    In the meantime, if you know how and if you have a couple of minutes, you could try a few of the previously commited versions ('git checkout') and see if there is any point at which this issue starts. This would help greatly.
     
  39. Vallar

    Vallar

    Joined:
    Oct 18, 2012
    Posts:
    177
    I don't know Git all that well, sorry. I can push, pull only. However, if you can tell me what to do exactly, I am more than willing to help out. I actually did a pull and switched to the target commit I wanted to test and didn't find the .DLL files.

    That said, I do recall that from day 1 this problem occurred and I am sure the version I used is from 19th of August (first version this happened in).
     
  40. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Oh okay. Then let's just wait until I release the bugfixes-only version and see if it still happens there. Will try to do that asap.
     
  41. Vallar

    Vallar

    Joined:
    Oct 18, 2012
    Posts:
    177
    Great, thanks a lot. Looking forward to the fixes.
     
  42. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Progress: working on said bugfixes-only release, applying everything to 2017.1 and 2017.2. So far:
    upload_2017-12-10_19-3-5.png
     
    shamsfk, Vallar and Deleted User like this.
  43. shamsfk

    shamsfk

    Joined:
    Nov 21, 2014
    Posts:
    307
    That is very cool!
     
  44. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
  45. Vallar

    Vallar

    Joined:
    Oct 18, 2012
    Posts:
    177
    Thanks for the fixes only version. I tried the 2017.1 version and had the same issue. Here is the exact error:

    Code (CSharp):
    1. ClientDisconnected due to error: Timeout
    2. UnityEngine.Networking.NetworkIdentity:UNetStaticUpdate()
    Note that I set Timeouts in NetworkManager to Connect Timeout = 4000, Disconnect Timeoout = 4000, Ping Timeout = 1000. Both default values and the edited ones produce the same error.

    I tried with both an exported Windows build acting as a client and editor a server as well as Windows build acting as server and editor acting as client.
     
  46. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Maybe there's a firewall/antivirus issue going on?
     
  47. Vallar

    Vallar

    Joined:
    Oct 18, 2012
    Posts:
    177
    I don't have a firewall -- well except Windows Firewall and that even has an exception for Unity. That said, this is localhost not over the internet.
     
  48. angusmf

    angusmf

    Joined:
    Jan 19, 2015
    Posts:
    261
    @Vallar maybe I'm confused about your issue, but it sounds like you are trying to connect to a websocket host from a standalone client. AFAIK, that isn't possible (maybe the Unity versions where this worked actually had bugs.) Somewhere on the Multiplayer forum, I think the LLAPI dev stated that on the client, WS vs UDP is selected in the LLAPI for you. You don't have the option to connect over websockets from a desktop client. If you try connecting from a webgl client you can verify that websocket connections do work. To connect to the same server you have to start both UDP and a websocket host (not possible with vanilla HLAPI or "Pro")
     
  49. Vallar

    Vallar

    Joined:
    Oct 18, 2012
    Posts:
    177
    OK let me see if I understand this correctly, if I enable the UseWebSockets option in the NetworkManager it is ONLY going to work on WebGL? If I disable that all other types work?

    That looks like a really limiting issue. What if I want to release a game on WebGL and mobile like Agar.io or Slither.io for example. I have to create 2 different builds and run 2 different servers or run 2 instances on 1 server?
     
    Edan-Smith likes this.
  50. angusmf

    angusmf

    Joined:
    Jan 19, 2015
    Posts:
    261
    Yes. HLAPI has a single property to represent the host that it uses whenever dealing with the LLAPI. That can be set to either a ws host or udp, but obviously not both. If you want both, the API suddenly has to deal with two hosts, so it has to do all operations on both hosts (such as syncing position or variables across clients,) or know which one is needed for the operation. You would have to start specifying a host for some types of communication, like when sending a message to a specific client.