Search Unity

Unity Multiplayer [Official] Multiplayer Improvements

Discussion in 'Connected Games' started by Erik-Juhl, Mar 10, 2016.

  1. DSS32

    DSS32

    Joined:
    Jan 30, 2015
    Posts:
    16
    Hello all well. I have a script in my player, and I'm trying to use the Asset Store network Lobby, but when I do the host, the control works in both Player and Player (Clone) prefab, How to solve?

    using UnityEngine;
    using System.Collections;
    using UnityEngine.Networking;

    public class carController : NetworkBehaviour {




    public HingeJoint2D frontwheel;
    public HingeJoint2D backwheel;

    JointMotor2D motorFront;

    JointMotor2D motorBack;

    public float speedF;
    public float speedB;

    public float torqueF;
    public float torqueB;


    public bool TractionFront = true;
    public bool TractionBack = true;


    public float carRotationSpeed;



    public Rigidbody2D rb;
    public Rigidbody2D rodaB;
    public float velocidade=0.0f;
    public float velocidadeback=0.0f;
    public bool noChao;
    Animator anim;



    // Use this for initialization
    void Start () {
    noChao = false;
    Debug.Log ("no ar");
    //anim = GetComponent<Animator> ();
    rb = GetComponent<Rigidbody2D>();
    //rodaB = GameObject.Find ("bikeroda").GetComponent<Rigidbody2D>();
    //rodaB = GetComponent<Rigidbody2D>();
    //backwheel = GameObject.Find ("bikeroda").GetComponent<HingeJoint2D>();
    anim = GameObject.Find ("Ciclista").GetComponent<Animator> ();
    }

    // Update is called once per frame
    void Update () {


    if (Input.GetKey (KeyCode.W) && noChao == true && Input.GetKey (KeyCode.S) == false )
    {
    rodaB.freezeRotation = false;
    rb.gravityScale = 5;
    backwheel.useMotor = true;
    if (TractionBack) {
    motorBack.motorSpeed = speedF * -1;
    motorBack.maxMotorTorque = torqueF;
    backwheel.motor = motorBack;
    //transform.Translate (Vector3.forward * velocidade);
    rb.AddForce(transform.right * velocidade);
    anim.Play("pedalando");
    }

    }
    if (Input.GetKeyUp (KeyCode.W))
    {
    backwheel.useMotor = false;
    }
    if (Input.GetKeyUp (KeyCode.S)|| noChao == false)
    {
    rodaB.freezeRotation = false;
    rb.gravityScale = 5;
    }

    if (Input.GetKey (KeyCode.S) && noChao == true && Input.GetKey (KeyCode.W) == false )
    {
    rodaB.freezeRotation = true;
    rb.gravityScale = 40;

    anim.Play("paradoP");

    }

    if (Input.GetAxis ("Horizontal") != 0 && noChao == false) {

    GetComponent<Rigidbody2D> ().AddTorque (carRotationSpeed * Input.GetAxisRaw ("Horizontal") * -1);

    }

    }

    }
     
  2. wobes

    wobes

    Joined:
    Mar 9, 2013
    Posts:
    669
    I want to say thank you too, for finding bugs in Unet, your posts very useful!
     
    isidro02139 likes this.
  3. lucasmontec

    lucasmontec

    Joined:
    Apr 7, 2015
    Posts:
    94
    Expose scene loading process in the NetworkManager... It has been requested before, we are waiting.
     
  4. IXNet

    IXNet

    Joined:
    May 31, 2017
    Posts:
    4
    At the very least make SceneId's consistent and deterministic, unique across scenes. The current mechanism ensures you can't run editor -> editor (which would really be a huge time saver rather than having to make builds all the time) and ensures the additive scene loading tools in unity are effectively useless.

    Ensure isLocalPlayer is available in OnClientStart.

    I agree with lucasmontec, the strong bond between scene and the network manager is very difficult to work around the way things are now.

    Fix the NetworkTransform.

    While it can be worked around it would be convenient to have a mechanism to allow NetworkIdentities to be dynamically bound and registered on a GameObject.
     
  5. georgeq

    georgeq

    Joined:
    Mar 5, 2014
    Posts:
    478
    I'm an indie game developer, working with Unity professionally full time for over the last 3 years. I'm trying to extend an existing game to support multiple players, simultaneously.

    A few weeks ago I started to explore the new Unity Networking system, the learning process has been quite difficult compared with other aspects of the engine, mainly because the lack of documentation, there's a lot variables and methods documented at the bare minimum or even less, incomplete examples or code without a clear enough explanation, just take the case of the Network Lobby (Unity Essentials) which completely lacks of error handling, if you try implement error handling yourself and dig into the NetworkManager and NetworkLobbyManager you find information which is not accurate or incomplete, for example: OnClientError is never called if you try to connect to a non existing host or an invalid IP address like: 704.291.577.999, maybe it is only called when after a successful connection, but the manual doesn't mention that and there isn't a OnCilentConnectionFailed callback or similar, so, it's obvious to think any client connection error would be reported to that function. The worst part is when you google: "unity network error handling" and you will stumble upon this page, which generates more doubts that it solves, if I read that page, it makes me think that I need a NetworkTransport in order to be able to catch network errors, but how do I get one form a NetworkManager?, the documentation doesn't tell you that. Until now every attempt to find a way to catch network error has led me to unanswered questions like this one.

    If there's something bad with the networking system then it definitively is the documentation. I don't doubt you can build awesome stuff with this, however without the proper documentation it takes much more time that it should, and at some point one starts to wonder if it would be faster to develop your own solution.

    From my current point of view and experience, I think if you really want to improve this, you should put all your effort on the documentation.
     
  6. Brianqq345

    Brianqq345

    Joined:
    Mar 12, 2016
    Posts:
    36
    I think the fact that we cannot even view the code is the biggest problem. Trying to write a backend for an MMO is agonizing with unity. The entire Unet has to be ripped out, because it is not functional, and from there it is a lot of guess work because we do not no the interworking's of unity, nor is there any documentation to reference. So having to spend $75K to get the code is a big price tag. Having access to it would be great, but just being able to see it would be fine, or at least if you would just give us a hint. My programmer does have a masters degree, and had to setup military networks in combat zones. so he does know what he is doing, and we have managed get it done, but my god you make it way more difficult than it needs to be. I met a Unity employee that told me he knows exactly what the solution is, but his NDA would not allow him to tell us. So this is all about making us fork out $75K, stick with your multi player "$" option, of go nuts for several months.
     
  7. limjq44

    limjq44

    Joined:
    Sep 16, 2016
    Posts:
    10
    I would write a tutorial on how to implement your own Server application and host it on the cloud if there are enough people requesting it, but it will be using tcp which means it won't be applicable for those real-time games such as fps games, BUT that does not mean that I will not write a tutorial on using UDP to communicate between unity and the server.
     
  8. philwinkel

    philwinkel

    Joined:
    Jun 6, 2013
    Posts:
    298
    I don't know if unet is intended for MMOs. (when I think of mmos, i think world of warcraft, etc - i guess it depends on your definition). I feel any mmo developed in unity would probably need to use the transport layer / LLAPI. Which would take a lot of network coding, like you mentioned.

    With that being said, i agree with everyone saying UNET needs some serious love and attention. Most of it seems OK, but the network transform is really bad. In fact my network transforms used to work OK, but now they dont seem to work at all for replicating transforms.

    it's not very promising how unity isn't really giving much attention to the HLAPI. i havent used unity for over a year, and i came back and it seems like not much has changed or improved.
     
  9. Brianqq345

    Brianqq345

    Joined:
    Mar 12, 2016
    Posts:
    36
    Been talking to my coder, and he basically said when it came to the backend, everything Unity had to go, we are hoping with unity 2017.1 using .Net 4.6, it might be a little smoother, but at this point our backend will work with most all engines out there
     
  10. philwinkel

    philwinkel

    Joined:
    Jun 6, 2013
    Posts:
    298
    I was going to use Bolt, but it seems like exit games purchased it and the source code is no longer available, unfortunately... I don't trust building my game on top of closed source proprietary third party assets.

    I am coding my networking on top of the Transport Layer / LLAPI. Lots of coding involved, but it seems like the only way to go if your netcode and multiplayer experience is important. Sounds like your developer is doing something similar - probably a good decision.
     
  11. Che4Cuba

    Che4Cuba

    Joined:
    Jan 17, 2017
    Posts:
    31
    Who are you?
    A game development company in Sydney, Australia.
    What kind of game are you trying to build or would like to build?
    An MMORPG using uMMORPG as a base structure,
    How does Multiplayer fit into that? What use-cases do you have?
    It's a Massive Multiplayer Online Role Playing Game, Multiplayer is the key word there..
    What are the GOOD things about the new Multiplayer system you like?
    That you can only host small games from it............
    What are the BAD things about the new Multiplayer system you dislike?
    The HLAPI system needs some serious work, we cannot make multiple scenes due to read string bugs, Sync Var issues and a bunch of other problems. It is imperative that vis2k is assisted in whatever way as a community of over 100 people are relying on an issue that looks like it will never be resolved
    How can we make it BETTER?
    FIX IT ASAP
     
  12. Xype

    Xype

    Joined:
    Apr 10, 2017
    Posts:
    339
    Options, full featured, scalability. I know what I want to do with it, but this is an engine, my needs are not the only one. I have big dreams, I need monster capability to implement things, but I don't want to deal with a LLAPI, I prefer more understandable documented HLAPI's. However that being said it should still be just as easy as it is now for someone to just drag and drop a few things and have a simple 2v2 4v4 small no configuration needed server to shoot at each other on.
     
  13. YondernautsGames

    YondernautsGames

    Joined:
    Nov 24, 2014
    Posts:
    110
    I'm a bit late to the game, but I've been hammering away at UNet code for months now so have a few points.

    Who are you?

    I'm a solo developer with cross disciplinary skills. Jack of all trades, but mostly a programmer these days

    What kind of game are you trying to build or would like to build?
    Currently working on a multiplayer FPS template and tools for the asset store. I'm aiming for everything you would need to release a polished and feature complete online FPS that has rough parity with currently released games. Initial release will be focused mainly on tournament style gameplay, with further breadth added if it brings in enough customers. I'm very close to feature complete on the networking side, and have a few large art features to complete and a whole lot of testing and documentation before release.

    How does Multiplayer fit into that? What use-cases do you have?
    It's a core component. I have tried to design all the core FPS features using interfaces and keeping everything decoupled such that the framework is there for different use cases, but it will be released with both pure singleplayer implementations (no networking code at all) and UNet based multiplayer ready to go. I might add Photon or similar if there is the interest later, but I wanted any users to have everything they need in one package. The template does use a combination of HLAPI and LLAPI, giving a simple lobby based setup, but exposing controls for dedicated servers, lan ,etc to players through menus.

    What are the GOOD things about the new Multiplayer system you like?
    I like the core server-authorative model. It took me a while to get into good habits and the right mindset to consider my components from the perspective of client, server, and client/server at the same time, but I do like that now. I feel that the HLAPI shows a lot of potential and could be a huge time saver. Overall it seems that a lot of thought has gone into creating something flexible and powerful enough for almost every case. I'm also a big fan of the (relatively) recently added non-player local authority (I like to use mvc and similar so keeping character separate from player was a huge pain before that).

    What are the BAD things about the new Multiplayer system you dislike?
    There are a number of bugs that needs sorting (HLAPI espescially). I'll not list here as the ones that specifically affect me are in the issue tracker and have also been highlighted better by others. There is an ongoing feeling that UNet is just not polished enough to be ready for widespread adoption. I am spending a lot more time tracking down unexpected behavior in my code, and tracking it back to things in UNet that are either broken, counter-intuitive (usually for a reason, but still), or inconsistent between server-client-server/client. I don't get that with any other aspect of programming for Unity, but this is like hacking through a forest. 10 lines of code in Unity is 120 in Unet.

    UNetWeaver. Ugh. I get that it is part of making UNet programming lighter and easier for people, but it is a whole level of opacity on what is going on that can be a nightmare for all the things it happily breaks. I have to constantly keep in mind that it is going to come along and add a bunch of code on top of mine, and usher it into doing things correctly instead of trampling all over my inheritance heirarchies, etc. IMO the less work done behind the scenes like this, the better.

    How can we make it BETTER?
    There are a few ease of use things:
    • Stricter naming conventions on methods. I've taken to prefixing every method and variable with Server or Client depending on where it is used. There are a few cases where I've been tripped up assuming a method was intended for client because of the naming and it turned out to be a method called on server when interracting with a client
    • Make calling syncvar hooks in initial state an option in the attribute
      • eg: [SyncVar (hook="ClientSyncValue" callHookOnStart=true)]
    • Switch to modern style scene management. I much much prefer having a scene for my persistant objects and then loading / unloading other scenes additively
    • NetworkManager and NetworkLobbyManager make far too many assumptions about usage. They seem geared specifically towards casual / mobile games and it can take a lot of effort to work around that to follow models more appropriate to PC games (I guess console is mid-way between the 2). I would prefer a slightly more low-level network manager and then more ready-built options.
    • Either a UI NetworkBehaviour or an option for NetworkIdentity not to take transforms from the server. If you stick a NetworkBehaviour on a UI object, and the server is running at a different resolution to the client then that object could be anywhere. It's not a huge thing to work around but only once you've realised what's happening.
    Otherwise, it needs polish and it needs people using it and reporting bugs. Those bugs that are reported need to be fixed in a timely manner. The bugs that are reported that turn out to be "by design", in some of those cases the design needs looking at. If enough people are hitting that bug then the design either needs to be optional or better communicated. Don't screw over the widest use case to pander to a specialist/very specific one. Make that one the optional case instead.

    Lastly, the documentation needs lots of work. It's much better than it was, but there are various things in the scripting reference that need more than "This does that". Explanations of use cases and by-design quirks would go a long way to making development easier. I'd be happy to see some system for community contribution for this as I for one would be glad to flesh out the odd doc when something trips me up.

    Anyhow. I can't wait till it's as polished as the rest of Unity. Thanks for all the hard work
     
    Last edited: Sep 26, 2017
    hippocoder, nonom and Onsterion like this.
  14. nonom

    nonom

    Joined:
    May 1, 2014
    Posts:
    12
    I stopped using Unity3D , paid a year for nothing. Good luck, you are pretty near to understand me.

     
    MrLucid72 likes this.
  15. MrLucid72

    MrLucid72

    Joined:
    Jan 12, 2016
    Posts:
    633
    I'm still pretty salty, myself, about UNET even though I'm "in a better place" now with Photon. However, UNET helped me open my eyes to what Unity really is and how they treat their product. This is a product made by CEO's and obviously not made by actual game developers, unlike Unreal (where they make real AAA games that people want to play -- not games like "Tanks" that are made by 3rd parties and completely irrelevant to any actual-use tutorial), so if they experience bugs during actual-use scenarios, they seem to be fixed ASAP).

    UNET has helped me decide what game engine to use for my next game and defines how I explain to the countless people that ask me about my experience regarding Unity and if I recommend it.
     
    dadude123, Onsterion and hippocoder like this.
  16. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    25,476
    Yeah I agree, networking in Unity is a chore, and reflects poorly on the developers whom are hard working and don't deserve criticism.

    Because there's no proper solid example materials by an official source, just random gibberish, frankly, so UNet is not peripherally supported. It could also use some API tweaks, the weaver, the HLAPI - all done badly, and not in the slightest bit necessary given a single guy did TNet which has a pretty great and clean API. But then I am a noob at net.

    So unless Unity manages to start the ball rolling before the year is out I think I'm having to check the alternatives.

    Although Unreal is not the stable seas you think it is.
     
  17. Onsterion

    Onsterion

    Joined:
    Feb 21, 2014
    Posts:
    210
    It's a shame but sometimes the features that a graphics engine in 2017 should have and does not have is for the money, if this feature (UNET / Multiplayer) does not make any impact on sales, they will never use his resources for made a better multiplayer solution.

    If we open a donation of 1 to 50 dollars for Unity to make a correct and efficient multiplayer system? xD
     
    hippocoder likes this.
  18. iddqd

    iddqd

    Joined:
    Apr 14, 2012
    Posts:
    396
    Why don't you all just switch to Photon Thunder now that it's released? It uses the same API as Unet. I couldn't wait for the thunder release so I switched to Bolt.
     
  19. Onsterion

    Onsterion

    Joined:
    Feb 21, 2014
    Posts:
    210
    Because we love suffer :rolleyes: and we love Unity :)
     
    Last edited: Sep 29, 2017
    wobes likes this.
  20. MrLucid72

    MrLucid72

    Joined:
    Jan 12, 2016
    Posts:
    633
    Lol don't give them any money. They are not anywhere close to poor. Just ask John Riccitiello for 0.0000000000001% of his pocket change:

    https://venturebeat.com/2017/05/25/...raise-400-million-at-a-2-6-billion-valuation/

    Personally, I think the article above hurt them. Now it shows that they have all this power, but choose NOT to do anything.

    They can keep their promises and offer modules as advertised, if they wanted to - but they don't. They could fix bugs that have existed for years and unstable modules that were abandoned after being announced, being called "stable", but they don't. They could fix UNET to be as advertised, but they won't.

    The only difference between Unity and Windows Vista (in terms of stability) is that Windows 7 came after Vista: Will Unity make that stability jump? or will they continue to create fluff features, abandoning their core?
     
    Last edited: Oct 5, 2017
  21. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    25,476
    Will microsoft do the right thing and base future versions of windows on Linux? Who knows. But there are alternatives and yes, I have lost this analogy. It wiggled out of my grasp like a slippery... I'll stop now.
     
    chiapet1021 likes this.
  22. Brianqq345

    Brianqq345

    Joined:
    Mar 12, 2016
    Posts:
    36
    If anyone is interested in a stand alone MMO backend that ignores UNET let me know. We built it for EverFeud and will market it soon.
     
  23. MaZy

    MaZy

    Joined:
    Jun 29, 2012
    Posts:
    79
    What I would like to have is that I can remove functions which should't be on clients.

    The old way I liked it very much. I think I need to go LLAPI to make this.

    Example I client say net.ToServer("OpenDoor", idDoor). Some validations ofc should be there too.
    But the OpenDoor Functions SHOULDN'T on the client.

    So I could define when I want to compile

    Code (CSharp):
    1.  
    2. #if SERVER
    3. void OpenDoor(...) {
    4.   // some server things
    5.   if( player.CanOpen() )
    6.      ...
    7. }
    8. #endif
    9.  
    10. #if CLIENT
    11. void OnTryOpenDoor() {
    12.   net.ToServer("OpenDoor", doorId);
    13. }
    14.  
    15. void OpenDoor(...) {
    16.   // some client things
    17.   door.Open();
    18. }
    19. #endif
    So clients will never be able to see server codes...

    So another Example from Garry Newman who made Garry's Mod and Rust which is made even with Unity. The example is part of Rust.


    As you see they did what I mean. So the client never now something about RPC_TakeLock. but the client can send RPCs still to server. I hated this so much on the old network system and now with unet its completly removed.
    Maybe this is possible in the LLAPI but didn't check it exactly.


    More about this here: https://garry.tv/2016/02/18/rusts-networking/
     
  24. wobes

    wobes

    Joined:
    Mar 9, 2013
    Posts:
    669

    Custom defines: https://wobesdev.wordpress.com/2016/10/10/preprocessor-directives/
    Custom attributes: https://wobesdev.wordpress.com/2017/05/29/custom-attributes/

    Inspired by Garry himself
     
    MaZy likes this.
  25. hawken

    hawken

    Joined:
    Aug 22, 2013
    Posts:
    475
    I understand this thread may be unloved at this point, but I have returned to making a game using the HLAPI after a bit of a break since when it was first released (almost 2 years?)

    what are you making
    online brawler

    why use multiplayer
    it's online only

    who is you
    I make PC / console games.

    the good
    So far I'm having fun, and my game works.

    the bad
    [Command] errors on dedicated servers shouldn't throw an error. Currently we have to write 3 types of code right now: Clients, Clients who are also the server & Servers. I think it was mentioned in here but extending this somehow to adapt would reduce amount of already mind bending code one has to write.

    Could not get message for object. Sometimes when using Destroy, you get a bunch of errors and warnings on clients, it's not really needed, and often these alerts don't contain any useful information as the object has already gone so we don't know the net ID.

    Network profiler doesn't really tell you what is bad or good.

    the bettering

    - documentation
    - guides
    - manual
    - sample projects of different complexities (not video tutorials for beginners)
    - best practices look up

    I find the docs extremely lacking, the API is all good and fine, but knowing what code to use is confusing. The API can be used really well if you know what you are looking for... which I have to say I do not, I am usually looking for something I have never coded but know I need.
    A really nice big thick 500 page manual of all situations, types of game and so on would be hugely well received. That is something I think most of us would pay for, as gleaning information from the few samples that do exist leads to very slow development indeed.

    I'm going to continue using Unet, I like it. I want to master it, I hope the Unity team can document it's correct / preferred use a little more, as all that's really lacking is best practices for certain situations, it just assumes you know how everything works.
     
    Last edited: Oct 17, 2017
  26. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,245
    I agree, but you can do this:
    Code (CSharp):
    1. void Test()
    2. {
    3.     // do things
    4. }
    5. [Command] void CmdTest() { Test(); }
     
  27. wobes

    wobes

    Joined:
    Mar 9, 2013
    Posts:
    669
    What kind of error does it throw?
     
  28. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,245
    None, the guy asked how to call a Cmd on a server - that's how. By wrapping it.
     
  29. wobes

    wobes

    Joined:
    Mar 9, 2013
    Posts:
    669
    I was talking about
     
  30. trudeaudm

    trudeaudm

    Joined:
    Apr 17, 2013
    Posts:
    116
    I feel like I am stuck. My game is very dependent on Unity's 2D features and physics, but this forces me to use Unity's networking, which is so terribly setup that it is one of the last remaining things to sort out properly before my game can release.

    It is to the point I have people researching and doing proto development in other game engines to see if it might be possible to remake them game on a different engine with better networking.

    With Unity's current multiplayer we can't have a match up for more than 5-10 minutes before the server breaks and boots all the clients.
     
  31. Driiades

    Driiades

    Joined:
    Oct 27, 2015
    Posts:
    151
    @aabramychev Hello,

    I plan to re-work the HLAPI because all time I want something to do with it i can't. The feature that make my decision is that I can't Stop listening new connection with NetworkServer because NetworkServer is a wrapper for NetworkServerSimple and the function "STOP()" is not accessible.... (a really GOOD IDEA !!! ^^ )

    So I ask you and all, if you already plan to work on the HLAPI or if I can take the task for ... hum... 6 month on my free time ? If it's useless because you will work on it soon say me :) ?
     
    Last edited: Nov 2, 2017
  32. iddqd

    iddqd

    Joined:
    Apr 14, 2012
    Posts:
    396
  33. Driiades

    Driiades

    Joined:
    Oct 27, 2015
    Posts:
    151
    I speak about a real re-work. Not a bug fix.

    With new class, new system. Based on what exist because I don't want to totally break people habit. But for example you have this sort of things :

    -NetworkManager.singleton.client for accessing to client. But what for the server ? nothing.

    NetworkServer is a wrapper.. ok but some functions are not here like the Stop() function. (and no function to access to the SimpleServerSimple (seriously... this property name ?) property).

    In fact i don't understand NetworkServer and NetworkClient if they are already in the NetworkManager. It's just : hey use other and other singleton and maintain other and other wrapper.

    Same for NetworkIdentity disabled in the scene, they are not sync (not send at all) and cause problem. A work around exists by using reflection ... Why not re-work this ?

    NetworkManager has a bad design, same for registring function for messages. Why only one function per message ? (via client.RegisterHandler(...) )

    With things like this, I think a good re-work is necessary. (not all, NetworkBehaviour is great for example).
     
    Last edited: Nov 2, 2017
    iddqd and Onsterion like this.
  34. marcV2g

    marcV2g

    Joined:
    Jan 11, 2016
    Posts:
    115
    HLAPI Pro is amazing work but HLAPI is fundamentally garbage since between tying everything together with internal static methods and using post compile for serialization it is impossible to extend the functionality in any meaningful way.
     
  35. Driiades

    Driiades

    Joined:
    Oct 27, 2015
    Posts:
    151
    I will check this and propose other components / fix on the repository. It will be better for everyone :)