Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Showcase Mirror - Open Source Networking for Unity

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

  1. larus

    larus

    Unity Technologies

    Joined:
    Oct 12, 2007
    Posts:
    281
    Issue with weaver has been fixed (cecil name+version needed updating). It's better to send a mail/PM for me to notice messages faster (then I will get an email notification).
     
    rob_vld, xVergilx and nxrighthere like this.
  2. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,297
    Any progress on updating HLAPI Pro?
     
  3. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,352
    Thanks

    Just read the message, will try again now.

    In seconds. 0.1 = every 0.1 seconds = every 100 milliseconds
     
  4. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,352
    Update: uploaded HLAPI Pro 2017.2 - link can be found in the first post.

    Big thanks to everyone who supported HLAPI Pro on Patreon and to all the people who contacted me via PM.
     
    Last edited: Oct 25, 2017
    Deleted User, xVergilx and PhilippG like this.
  5. Deleted User

    Deleted User

    Guest

    Thank you so much for this update.
     
  6. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,297
    I've noticed something while I was re-reading initial post:
    There's this one;

    And this:

    Have you tried using FormerlySerializedAsAttribute? Applying refactoring to variables and then slamming this attribute allows easy re-serialization of variables. That might also help you chunk down some code. Just a thought.

    On offtopic note: Thanks for 2017.2 upgrade, it's awesome as usual :)
     
  7. Nox89

    Nox89

    Joined:
    Sep 3, 2017
    Posts:
    3
    Heya!

    First of all, thanks for spending time on improving the HLAPI, it's so needed and I'm really excited to use it for my own projects.

    I have a question. I just enabled HLAPI pro on one of my projects and noticed that my players are no longer synced at all. They use Rigidbodies and looking at the code in NetworkTransformBase that seems to be because you only update position for objects without rigidbodys: https://bitbucket.org/vis2k/hlapi-p...file-view-default#NetworkTransformBase.cs-570.

    Is this a bug/oversight or am I missing something obvious? I'm guessing the latter since others seem to be using it just fine :)

    Thanks in Advance!
     
  8. mightybob

    mightybob

    Joined:
    Mar 23, 2014
    Posts:
    75
    Hey, just tried this out on Unity 2017.1. Big problem: anywhere in the code where I assign a value to a SyncVar results in this error:

    Code (CSharp):
    1. InvalidProgramException: Invalid IL code
    Does anyone know why? Seems like a massive thing for SyncVars to not even work, unless you have some custom syntax for SyncVars I'm not aware of.
     
  9. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,352
    That might work yes

    Thanks for letting me know, looks like FixedUpdate went missing during the previous NetworkTransformChild update.
    I added it again and uploaded the DLLs again. Should work now.

    Sounds like your UNET Weaver DLL wasn't replaced properly. SyncVars definitely work fine with HLAPI Pro.
     
  10. Kerrjgan

    Kerrjgan

    Joined:
    May 30, 2016
    Posts:
    10
    Thank you for the continued development!
     
  11. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,352
    You are welcome
     
  12. Nox89

    Nox89

    Joined:
    Sep 3, 2017
    Posts:
    3
    @vis2k Thanks for the quick fix. I'm out traveling for the week but i'll retest when I have some downtime.

    @mightybob & vis2k Yeah SyncVar seemed to work fine when I tested HLAPI Pro. Make sure you "move the Unity.UNetWeaver.dll to Unity.app/Contents/Managed/" as vis2k mentioned.
     
    mischa2k likes this.
  13. mightybob

    mightybob

    Joined:
    Mar 23, 2014
    Posts:
    75
    Thanks, I'll try this.

    @vis2k does HLAPI pro's Network Transform support 2d rigidbodies? Just curious.
     
  14. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,352
    Yes
     
  15. trudeaudm

    trudeaudm

    Joined:
    Apr 17, 2013
    Posts:
    116
    In general can Unet and this handle 100s of objects moving around on screen simultaneously?
     
  16. Driiades

    Driiades

    Joined:
    Oct 27, 2015
    Posts:
    151
    @vis2k I will probably check your HLAPI Pro next weeks. And I ask you if it's possible to propose modifications and other components to extend HLAPI ?

    I have like a NetworkingSystem in replacement for NetworkManager and NetwokedTransform / NetworkedRigidbody.
    Also some NetworkedTimer and things like that can be usefull to everyone but out of scope of the HLAPI (it's just an "extension" using the NetworkingSystem component)
     
  17. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,352
    Depends on a lot of things. HLAPI Pro doesn't make that much of a performance difference (if any) in comparison to HLAPI though.

    I try to keep compatibility with HLAPI so that people can swap back to the original one any day if necessary.
     
  18. trudeaudm

    trudeaudm

    Joined:
    Apr 17, 2013
    Posts:
    116
    I ask because right now I am dealing with the server going down after about 5 minutes, I think it is due to excessive messages. Not really sure why this would make the server go down though. I would have expected it just to lag out.
     
  19. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,352
    If it happens with the original HLAPI too then it's probably best to report a bug to Unity.
     
  20. Nox89

    Nox89

    Joined:
    Sep 3, 2017
    Posts:
    3
    Sorry for the late reply, last week was a hectic one.

    Just wanted to let you know that synchronization of rigid bodies seem to work fine after you latest fix. Thanks for the support!
     
  21. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,352
    Good to hear!
     
  22. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,352
    Are you sure this is a bug? It says that "This fixes OnStartAuthority not being called on server for objects with the m_LocalPlayerAuthority flag set." - but as far as I understand, localPlayerAuthority = true means that the client has the authority, so OnStartAuthority should not be called on the server at all.
     
  23. angusmf

    angusmf

    Joined:
    Jan 19, 2015
    Posts:
    261
    Sorry if I missed this being addressed, but isn't that forbidden by the current "license"?

    ---edit---
    On that note, great project and thank you. I'd be more grateful if the code was MIT licensed like the Unity repo. If it weren't for that, I would at least try it. I'm with some of the others, probably also folks that already use the Unity implementation, in being a little leery of some of your "readability" or "general improvement" changes that don't address actual bugs. I don't have any reason to think they're worse than the original code, but don't have any reason to think otherwise either. For that reason alone it would be especially nice to have a "free" license so I would at least feel cool about cherry-picking changes from your repo. As it is, if I wanted something like your scene change fixes, I would need to read over your code, understand it, and re-implement on my own. That comes with benefits of course, but it would be nice to have the option to just copy your code.
    But really, thanks for even going there! If nothing else, you're showing folks that the HLAPI is a very useful place to start for some projects and providing an example showing that debugging and fixing it is something "anyone" can do.
     
    Last edited: Nov 11, 2017
  24. angusmf

    angusmf

    Joined:
    Jan 19, 2015
    Posts:
    261
    Setting localPlayerAuthority flag does not grant authority, but it does have to be set to true to add authority. The only way to acutally give the client auth is by spawing it as a player or by adding authority (NetworkIdentity.AssignClientAuthority or AddPlayerForConnection/ReplacePlayerForConnection.) Setting the hasAuthority flag in OnStartServer (or anywhere but where you are setting authority) results in problems. Coincidentally, I just left a more detailed comment on the PR.

    I don't know how your various assets deal with this issue, or if they do, but without that fix, it is impossible to grant/remove authority to an object at-will. The states of hasAuthority becomes (actually starts out) out of sync, so the internal check on whether authority is granted gives the wrong result. Not to mention that hasAuthority is unreliable for use in user code.

    Worth mentioning that OnStartAuthority and OnStopAuthority are meant to run client and server side.

    ---edit---
    If anyone read all that, sorry for all the edits. It's a subtle issue, but feels like a brick wall as soon as you try to remove auth from something...
     
    Last edited: Nov 11, 2017
    nxrighthere likes this.
  25. MCoburn

    MCoburn

    Joined:
    Feb 27, 2014
    Posts:
    71
    Some questions:

    What is the correct way to change scene to the initial scene I want people to connect to as the Host starts? Should I use OnStartHost() to call ServerChangeScene() or do you have another idea?

    Could you please elaborate on what OnClientError and OnServerError do exactly? From what I can see, the documentation says that they report errors like a client timeout, etc. Do they do just that or do they immediately pull the pin after an error occurs? In addition, the most common one I've seen is "Client disconnected on error: Timeout". Is it possible to give a more descriptive text, and is this error stored anywhere so I can cache it and display it to the end user in a neat manner (so if they continue to get the error, they can file a bug report)?

    Is the "Failed to send buffer bytes: 8" error that appears when you do a unclean disconnection (ie. Alt+F4 the client instance if standalone) able to be squashed? This one also appears with WrongConnection blah blah after it.

    I'm continuing to evaluate your improved library, and so far it's been a ray of light into the darkness that is HLAPI. :D

    EDIT: Found another issue. Seems the DLL for Unity 2017.2.x doesn't replace the Network Transform options? Or did I place a DLL in the wrong place? This is what I still see:
    Unity_2017-11-12_17-16-29.png

    EDIT 2: Ignore the above edit, I was stupid. I overwrote the DLLs of Unity 5.6.3 on my C Drive, instead of Unity 2017.2 on my S Drive. Could you please ensure that the first post has a line that says "Default unity installation or wherever you installed it to" so that others don't make the same mistake I did?
     
    Last edited: Nov 12, 2017
  26. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,352
    I recommed the UNET manual to learn how OnStartHost etc. work - I didn't change that part.

    It will fail to send bytes if the other person disconnected, that's okay, I wouldn't worry about it. Happens in the original HLAPI too as far as I know.

    Yea sorry about the license part, this will be a bit difficult.
    We will need a stable HLAPI for the next 5-10 years while everyone works on their multiplayer games. This is highly important for my own projects and I suppose for all of you guys as well. HLAPI will need a lot of attention during that time.

    The MIT license is great - but maybe a 'pay what you want' or 'free for personal use' license or putting it on the Asset Store would greatly increase the amount of hours I can invest into this. Hence my hesitation.

    I am not going to sue anyone though, so I wouldn't worry about it too much for now.
     
  27. angusmf

    angusmf

    Joined:
    Jan 19, 2015
    Posts:
    261
    Interesting. If you have the resources to test/profile (keeping in mind you already depart significantly from Unity's coding standards, whatever they are...) and support the API as a commercial product, that would be significant. Even better would be to also provide an alternative cloud build service in which UnityExtensions can be replaced. That doesn't really look likely at this point, but correct me if I'm wrong. OTOH, I wonder how long it will really take for Unity's data-oriented programming push to reach the LLAPI, likely rendering the HLAPI obsolete (especially for projects like your own uMMO*, etc.)

    In the meantime, I want to be explicit about how I'm taking your comments: as irrevocable permission to merge changes from your published repo to my private fork with the understanding I don't redistribute source or my own standalone networking library based on your source without some new license agreement.
     
  28. MCoburn

    MCoburn

    Joined:
    Feb 27, 2014
    Posts:
    71
    One other thing I noticed, and I'm not sure if this has already been fixed, is that if you get a connection coming in, the appropriate connection is added/updated in the NetworkServer.connections array.

    An active connection is able to be accessed fine by going through the list with a foreach or a for loop, but as soon as one drops off, it turns into a null object. Then when another client connects, that null object turns into it's connection. Is this intended behaviour (ie. recycling memory) or is this a "by design" thing?

    For example:

    NetworkServer.connections[0] = localClient
    NetworkServer.connections[1] = 10.0.0.1

    Now connection 1 drops off.

    NetworkServer.connections[0] = localClient
    NetworkServer.connections[1] = null

    Now a new client connects in from a different IP.

    NetworkServer.connections[0] = localClient
    NetworkServer.connections[1] = 10.0.0.2

    I guess it saves some sort of microlag when the array expands with a new connection?

    I don't think this is a really bad issue, but I know it's messed me up when I thought only 2 connections would present in the array but there's a null third one because it didn't remove the entry.
     
  29. angusmf

    angusmf

    Joined:
    Jan 19, 2015
    Posts:
    261
    That is by design. The LLAPI assigns the connection IDs and according to aabramychev keeps them in an array internally. I think the LLAPI is actually implemented in the C++ "layer".
     
  30. MCoburn

    MCoburn

    Joined:
    Feb 27, 2014
    Posts:
    71
    Are some HLAPI functions that can be overridden stubs? I noticed that while overriding some in my code if I called the base function that it doesn't work, but if I remove "base.OnClientReady" as the last line the overridden code works fine.
     
  31. angusmf

    angusmf

    Joined:
    Jan 19, 2015
    Posts:
    261
    Some are, but some have code that you would usually want to run. The docs explain which ones are hooks and which are not, but I'm not sure it's completely accurate. It's best to look at the HLAPI source when not calling the base class to make sure you're not missing anything important.
     
  32. ScoobyNooby

    ScoobyNooby

    Joined:
    Nov 14, 2017
    Posts:
    45
    I would just like to thank vis2k for cleaning up HLAPI town.
    You are like the sheriff of HLAPI.
    The townsfolk no longer live in fear and no longer need to lock up their kids in fear of what HLAPI might do to them. :)

    And thank you to angusmf for your contribution too.

    Question directed at Unity.

    How many unity versions back are being updated with Vis2k changes? I'm using Unity 5.6.4 and so far ive seen no problems with the transform smoothness. I was wondering if this was because of the changes that sheriff vis2k has made?
     
  33. Stormy102

    Stormy102

    Joined:
    Jan 17, 2014
    Posts:
    495
    Unity seem to have a mythical workflow of GC-free code. As Vis2k is making the code simpler and easier to understand, he is also (allegedly) creating more GC (which tbh is virtually impossible to avoid). So you need to install it yourself - have a look at the first post in this thread for links which will help you do this.
     
  34. MCoburn

    MCoburn

    Joined:
    Feb 27, 2014
    Posts:
    71
    @vis2k In NetworkManager.cs, lines 243 to 255 inside the OnValidate() method, you have both:

    NetworkManager: First channel needs to be Reliable because in the code Channels.DefaultReliable is 0.
    NetworkManager: Second channel needs to be Unreliable because in the code Channels.DefaultReliable is 1.

    In my project to work around a scriptCRCMismatch condition due to channels the default channels being stupid (for no apparent reason in stock HLAPI) I'm using a function to clear the channels and then add two new channels which are QosType.ReliableSequenced and QosType.UnreliableSequenced. My project is a shooter and I need to ensure that packets are sequenced for obvious reasons. Is this going to mess things up or am I safe?

    EDIT: When a client disconnects, the address property ends up as a string.Empty. Is there a way we can get the IP address that just disconnected? This would be beneficial as I perfer to know what IP addresses are connecting/disconnecting.

    EDIT 2: Seems you've fixed the scriptCRCMismatch bug; great work.
     
    Last edited: Nov 15, 2017
  35. MCoburn

    MCoburn

    Joined:
    Feb 27, 2014
    Posts:
    71
    In addition, I'm getting issues where it seems that upon connecting to the server the connection is getting set to ready, but then since the server tells the client to change scenes I'm getting another "A connection has already been set as ready. There can only be one" error. This also happens even if I haven't overridden OnClientChangeScene.

    EDIT: This issue I think causes two player objects to be spawned. On the host, there is 3 player game objects (the prefab it spawns when the player is loaded) present on the scene, but on the client that just errored with that message, only the host is visible.

    Do you need to add a check to ensure that if you're not ready, that you ready the connection somewhere?
     
    Last edited: Nov 15, 2017
  36. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,352
    Hi guys, sorry for the late replys, sometimes the Unity forum doesn't notify me for some reason.
    You should really use 0 = relaible, 1 = unreliable because the HLAPI assumes that in the code everywhere. You can change it if you want, but I'd recommend using channels [2],[3] etc. for your custom ones.

    About the IP address: can you post a simple example to look at? Like in OnDisconnect somewhere?

    Only in HLAPI Pro or in HLAPI too?
     
  37. MCoburn

    MCoburn

    Joined:
    Feb 27, 2014
    Posts:
    71
    Ok. No worries, I'll set them in the channels in the Network Manager and leave them alone.

    Certainly:

    public override void OnServerDisconnect(NetworkConnection conn) {
    print(string.Format("Bye bye #{0} ({1}) ! It just disconnected from the server.", conn.connectionId, conn.address));
    base.OnServerDisconnect(conn);
    }


    It will output:

    Bye bye #2 () ! It just disconnected from the server.

    Ideally it should say an IP address between the brackets.

    Only in HLAPI Pro this two-spawn + double ready issue occurs. I had my project spawning fine before I dropped in HLAPI Pro.
     
  38. lucasmontec

    lucasmontec

    Joined:
    Apr 7, 2015
    Posts:
    97
    Hey, how are you?
    First, thanks for this mountain of fixes. You are saving lives here!
    I wanted to point out an easy addition to HLAPI Pro:

    https://answers.unity.com/questions...ctive-objects-on-new-clients.html?sort=votes#

    Networked objects aren't spawned for newly connected clients if they are disabled on the server. This is an issue when pooling is used for NW objects on the server, or when the object must be disabled as part of its behaviour. This unity answer already has a fix that has one draw back (when the object is spawned, its disabled state is not kept on the client). This can be added to the net identity easily. What do you think about this?

    I have implemented this 'fix' on my game. When a player connect I send him a list of objects to disable (so the disabled state is correctly maintained).
     
    Natalynn and angusmf like this.
  39. Driiades

    Driiades

    Joined:
    Oct 27, 2015
    Posts:
    151

    Same here, this "fix" is easy to be done. Maybe send gameObject with a boolean to say it's disabled/enabled but always send it !

    It cause a lot of bug when you want to enable this by command/rpc and the client doesn't have it spawned.
     
  40. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,352
    Will look into the IP address part - maybe there's a good reason for that, will see.

    Can you also give me a simple example to reproduce that ready thing?

    I don't really want to mess with disabling/enabling GameObjects since UNET does that internally too (NetworkProximity etc.) - might be too risky to overwrite something that we shouldn't. At least for now.

    Probably inherited from the original HLAPI - but will look into it, might be worth a fix.
     
  41. Artaani

    Artaani

    Joined:
    Aug 5, 2012
    Posts:
    423
    Hello. Small bug report.
    I found this issue in the original UNET, but this is still persists in the UNET HLAPI Pro.

    If I will create a function, for example:

    [Command]
    public void DoSomething () {

    }

    After compilation, the console will tell me that I forgot to add "Cmd" prefix before name of the function.
    However, this error in the console will not block "Play" button. For example I can just press "Clear" in the console. Red error will be removed, and I am will be able to press "Play" and run. And user will have no idea why RPC is not working because console is empty.

    In order to show this error again, I need to change any symbol in the code and recompile it. Error will be generated again.


    This was really confusing during first attempt of working with UNET. Can you do something with it?
     
  42. Artaani

    Artaani

    Joined:
    Aug 5, 2012
    Posts:
    423
    Also, I think this is definitely not right if one man trying to fix entire network system which should be done by big team of developers with full salary.

    I'm embarrassed to ask you about anything.
     
  43. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,352
    Update:
    • [2017-11-16] NetworkConnection.Disconnect doesn't clear .address anymore so it's available in NetworkManager.OnServerDisconnect
    @MCoburn

    I think that's a new Unity feature (or bug?). It seems to play the last working version if you press play while still having errors.

    Someone has to fix it
     
  44. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,352
    Where exactly did you find that code? In which DLL / namespace?
    I looked through the Weaver and found the place that generates those write functions, but there's no obvious reason from what I saw.
     
  45. Artaani

    Artaani

    Joined:
    Aug 5, 2012
    Posts:
    423
    No, it is a bug. In all other cases, if I have red errors in the console, editor will not allow me to press Play until compilation error will be fixed.
     
  46. Driiades

    Driiades

    Joined:
    Oct 27, 2015
    Posts:
    151
    It's not a compilaiton error. It just say that HLAPI will not send your command because it's not prefixed.

    But a show each time you clear console will be better.
     
  47. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Its not a compilation error at all though. Unity is telling you that one time that there is a problem because you're not going to get the behavior you're looking for, but the code compiles just fine.
     
  48. MCoburn

    MCoburn

    Joined:
    Feb 27, 2014
    Posts:
    71
    It is kinda hard to do so without sending you the full project that is affected. I will see if I can make it error in a different project for debugging, otherwise I will have to send you a copy of the project and instructions on how to make the error happen.
     
  49. MCoburn

    MCoburn

    Joined:
    Feb 27, 2014
    Posts:
    71
    I was successfully able to replicate the double ready bug in a completely different project. I will upload the very small project to my server for you to take a look at and debug.

    EDIT: Uploaded and sent to you on Discord.
     
    Last edited: Nov 17, 2017
  50. angusmf

    angusmf

    Joined:
    Jan 19, 2015
    Posts:
    261
    I might be confused about the issue, but I don't run into it with pooling AFAIK. Using the NetworkServer spawn handlers, I never spawn a disabled object. It may seem a little clumsy, but when I pull a NW object from the pool, which enables it, it also calls NetworkServer.Spawn. When the object is spawned on the client, the spawn handler is called which pulls from the pool on client. Destroy sort of does the reverse.