Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. Unity 2020 LTS & Unity 2021.1 have been released.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Unity Multiplayer The open source MLAPI project joins the Unity family.

Discussion in 'Multiplayer' started by CreativeChris, Dec 3, 2020.

  1. luke-unity

    luke-unity

    Unity Technologies

    Joined:
    Sep 30, 2020
    Posts:
    62
    I can understand why you are confused. We aren't currently at a state yet where we can provide a roadmap or time frames for MLAPI. Once we have our first Unity release of MLAPI we will be able to provide documentation for the new features we are working on.

    Regarding our changes, some of them are quite substantial and will break backwards compatibility with the current version of MLAPI. We will provide guides and support for upgrading your projects which will hopefully make upgrading less painful.
     
    tik_tikkers and MartasX like this.
  2. optimise

    optimise

    Joined:
    Jan 22, 2014
    Posts:
    720
    Hi @CreativeChris. Can I know when matchmaking, login & register player account, store player profile, store player persistent data, leaderboard and etc multiplayer features will be available? I think the development has been started at 2018 since the announcement but until now I still didn't get the features yet. Currently my mobile game project is using DOTS netcode to develop. I need the remaining multiplayer features to make it as a complete multiplayer game.
     
  3. yoonitee

    yoonitee

    Joined:
    Jun 27, 2013
    Posts:
    2,332
    My feature request for MLAPI so far:
    • Not having to spawn synced game objects (Edit: you can do this already*)
    • Easy way to stream player input from client to server (Edit: just an idea)
    • (Basically make it more like the NetView model!)
    Transports for:
    Extras:
    • A way to exclude different libraries (e.g. steamworks.dll from different builds)

    So you can make use of the relay servers of each of these platforms. Plus easy way to exclude each of these libraries from the build (e.g. exclude Steamworks library). So you can easily target the networking to particular platforms.

    Also if a workable version could be done by summer that would be cool :D

    (P.S. I know Steam/Unreal etc. all have their own leaderboard/matchmaking API, maybe there should be some unified way to target each of these? Or is that too complicated?)

    *Can cause KeyNotFound exception if host is not started.
     
    Last edited: Jan 11, 2021
  4. mhernandez88

    mhernandez88

    Joined:
    Jul 20, 2016
    Posts:
    36
    I think you misunderstand transports. Transports are simply the socket wrapper that handles the sending and receiving of data. Unreal / Discord would not be transports. I believe LiteNetLib can run crossplatform, don't quote me however.
    Also you do not have to spawn synced game objects, you can use PrefabSync
    Player Input is pretty easy to send via messages, doubt it could be made easier.
     
  5. yoonitee

    yoonitee

    Joined:
    Jun 27, 2013
    Posts:
    2,332
    You are right. When I said "Unreal" I meant "Epic Online Services". Which have exactly that functionality. (It is quite new) Discord seems to have the same. But I am less familiar with it.

    Basically they are all pretty similar it's just that the messages are relayed through different companies servers. But you have to use their SDKs.
     
    Last edited: Jan 10, 2021
  6. luke-unity

    luke-unity

    Unity Technologies

    Joined:
    Sep 30, 2020
    Posts:
    62
    Thanks, your feedback is appreciated. Could you elaborate on your requests so that we can make sure that we are on the same pace?
    • "Not having to spawn synced game objects" You shouldn't have to do that. MLAPI spawns networked objects automatically on clients so that they match the server objects. All you have to do is create networked objects on the server and call Spawn on them.
    • "Easy way to stream player input from client to server" This can be done by just invoking a ServerRpc currently. Or where you thinking about another way of sending input?
    • "(Basically make it more like the NetView model!)" I'm not very familiar with RakNet's NetView but if I'm not mistaken then the basics like transmitting data via RPCs work pretty much the same. Could you eloborate on what features from NetView you are looking for?

    Regarding future transports for MLAPI. We will provide ways to connect to consoles/mobile devices and having a transport which is cross platform compatible is important for us. It is unlikely that we will officially support platform specific transports for Steam/Epic/Discord/Oculus etc. We have a transports repository where anyone can contribute their transports and we hope that over time this will allow us to cover some of these platforms specific implementations.
     
  7. yoonitee

    yoonitee

    Joined:
    Jun 27, 2013
    Posts:
    2,332
    • "Not having to spawn synced game objects" You shouldn't have to do that. MLAPI spawns networked objects automatically on clients so that they match the server objects. All you have to do is create networked objects on the server and call Spawn on them.
    In the old NetView NetworkView model you could just add a NetworkView component to an object in the scene and it would sync up transforms etc. As far as I can tell in the MLAPI model, you have to create prefabs, delete them from the scene, add them to a prefab array and they are recreated at runtime. If you can sync things in the scene without deleting them from the scene then I don't know how to do it currently.
    • "Easy way to stream player input from client to server" This can be done by just invoking a ServerRpc currently. Or where you thinking about another way of sending input?
    Yes you can do it using ServerRpc, but perhaps there would be a higher level way to simply stream all configured inputs from client to server. And on the server you could just do something like: GeyKeyDown(clientID,key). Instead of having to write all that code yourself. Just an idea. Not sure if its a good or bad idea.
    • "(Basically make it more like the NetworkView model!)" I'm not very familiar with RakNet's NetworkView but if I'm not mistaken then the basics like transmitting data via RPCs work pretty much the same. Could you eloborate on what features from NetworkView you are looking for?
    In the NetworkView model you didn't have to create prefabs of objects just add a NetworkView component to them and they would sync the transforms or animations. It was very simple. No prefab arrays, or default player prefabs etc.

    Another thing I noticed is that if you don't set a default player object, other objects that you spawn aren't synced. Not sure if this is a feature or a bug. The whole "default player" prefab thing is confusing to me. What if your game consisted of more than one player controlled object per player?

    P.S. You can try out the NetworkView component up to Unity 2018.1. It still works. e.g. make the server on localhost.

    PPS. I would say that apart from writing transports there needs to be a system to hide libraries from different SDKs, so you can build your game for different systems. Not sure if you can do this yet. (e.g. hide Steamworks.dll when building for mobile)

    PPPS. Maybe the companies such as Steam/Epic/Discord/etc. will supply their own transport layers?
     
    Last edited: Jan 10, 2021
  8. brunocoimbra

    brunocoimbra

    Joined:
    Sep 2, 2015
    Posts:
    588
    This isn't exactly what SoftSync does? https://mlapi.network/wiki/object-spawning/

    Not sure how exactly MLAPI handles that specifically (however what you mentioned first seems like a bug to me), but in Mirror or UNet you would put on the "Default Player" prefab the prefab that represents the player that is connected to the server, not a specific character or object, which then would spawn the chosen character/objects (or multiple characters/objects). That player could ie be the container for stuff like the player's nickname, kill count and other per-player data.
     
    yoonitee likes this.
  9. mhernandez88

    mhernandez88

    Joined:
    Jul 20, 2016
    Posts:
    36
    "Default Player Prefab" is just another way of saying "Spawn Some Client Side Authority Object" for instance
    => Client connects to server
    => server spawns "PlayerPrefab"
    => server syncs scenes
    => client listens for scene load
    => on scene load client checks game state
    => on client (PlayerPrefab) sends RPC to server SpawnMyCharacter
    => server spawns all character associated prefabs with or without transferring ownership

    So for instance the server can spawn ( For authoritative )
    1. CharacterCamera ( server authority )
    2. CharacterController ( server authority )
    3. PlayerInputController ( client authority )

    For non-authoritative
    1. CharacterCamera ( client authority )
    2. CharacterController ( client authority )
    3. PlayerInputController ( client authority )
     
    yoonitee likes this.
  10. mhernandez88

    mhernandez88

    Joined:
    Jul 20, 2016
    Posts:
    36
    And for Discord, I would not worry about trying to use it as a transport. I would instead use it as a lobby / chat service.
     
  11. luke-unity

    luke-unity

    Unity Technologies

    Joined:
    Sep 30, 2020
    Posts:
    62
    The reason why people like to use Discord or Steam for transports is because they provide free relay servers for p2p hosting. Else they would have to self host those servers or use one of the paid relay services.
     
    yoonitee likes this.
  12. MrG

    MrG

    Joined:
    Oct 6, 2012
    Posts:
    338
    Mirror has a Discord transport but since Discord shut down their game shop that would be the feed path to players, it's rather pointless now.

    @yoonitee Mirror has all the transports you mentioned except Oculus / Facebook. I'm sure that can be considered, though.
     
    yoonitee and luke-unity like this.
  13. yoonitee

    yoonitee

    Joined:
    Jun 27, 2013
    Posts:
    2,332
    Thanks. You are right. However, when I put a NetworkedObject and a NetworkedTransform on an object and leave it in the scene it works but I get a "KeyNotFoundException". (Until I start the host or server.) But it is fine after that. (And it only works if I have a default player prefab in my prefab array - I just make an empty GameObject prefab with a NetworkedObject component on it). One way to avoid these errors is to disable all NetworkedTransform components until the server starts but that isn't ideal.

    MLAPI version 12.1.7

    Also anyone know what a "multi project setup" is? I never heard this phrase before.

    Yeah, I couldn't really see Discord ever taking off as a game distributer.

    I hope someone does make a transport for Oculus for Mirror! Is there somewhere I can make a request? If not when my Oculus arives in a few days I may have a go myself at making one. But I'd prefer to leave it to the experts! I'm really motivated to make a multiplayer VR game.
    Exactly. I currently have a Azure cloud instance hosting a facilitator to make p2p connections. But it is not an ideal solution because (1) you pay for it (2) i don't know if it will scale well (3) it is not 100% effective at nat-punchthough. So in future games I want to transition to services like Steam/Epic. The downside is I'm not sure if crossplatform mutiplayer is possible.

    P.S. I think MLAPI is usable as it is, it just needs better documentation and tutorials. I would suggest making a short tutorial on it as it is now. Even though it might change in 6 months time.
     
    Last edited: Jan 11, 2021
  14. MrG

    MrG

    Joined:
    Oct 6, 2012
    Posts:
    338
    Stop by Mirror's discord sometime to discuss :)
     
    alautiev and yoonitee like this.
  15. yoonitee

    yoonitee

    Joined:
    Jun 27, 2013
    Posts:
    2,332
    I am evaluating Mirror now. Both MLAPI and Mirror seem very similar. I think at the moment Mirror is tiny bit easier. But if you learn one you can understand the other. According to Unity Mirror has 3/5 for performance and MLAPI has 5/5 but I don't really know how that's measured (and what transports they used).
     
  16. vis2k

    vis2k

    Joined:
    Sep 4, 2015
    Posts:
    3,839
    It was not measured. The study was based on a survey.
     
  17. BizzBang

    BizzBang

    Joined:
    Mar 19, 2020
    Posts:
    2
    Is there a way I can contact you? I want to chat with you about the old MP system, if you don't mind.
     
  18. SweatyChair

    SweatyChair

    Joined:
    Feb 15, 2016
    Posts:
    140
    We decided to give MLAPI a shot over Mirror simply because of Unity's acquisition. And turn out a bit disappointed that that SteamP2PTransport hasn't been updated for 2 years and running few issues that seem not being taken care of. I hope they can keep the solution up to date and improving it.
     
  19. invisage

    invisage

    Joined:
    Jun 27, 2019
    Posts:
    14
    If I am looking to do communication between apps on wifi, would MLAPI be a good option to explore?
     
    Last edited: Jan 23, 2021
  20. dannyalgorithmic

    dannyalgorithmic

    Joined:
    Jul 22, 2018
    Posts:
    83
    Try Mirror
     
  21. JoNax97

    JoNax97

    Joined:
    Feb 4, 2016
    Posts:
    459
    No, don't do that. Mirror and MLAPI are fundamentally the same. Heavy realtime multiplayer frameworks made for a very specific situation.


    If you need to relay some messages over the network use HTTP communication or sockets
     
  22. Soulmate17

    Soulmate17

    Joined:
    Dec 29, 2020
    Posts:
    1
    Thanks for that trick! Were you able to find a proper way of dealing with NetworkedTransform for objects in the scene? Error info hints at the channel name issue, but adding the channel name to the transport manually had no effect.
     
  23. yoonitee

    yoonitee

    Joined:
    Jun 27, 2013
    Posts:
    2,332
    Unfortunately, I've put multiplayer to one side at the moment. I've decided to try Oculus game dev a try. Incidentally, the Oculus asset in the asset store has a multiplayer demo, but that might be using special Oculus multiplayer code. I haven't checked yet.
     
  24. erkneren

    erkneren

    Joined:
    Apr 28, 2020
    Posts:
    10
  25. luke-unity

    luke-unity

    Unity Technologies

    Joined:
    Sep 30, 2020
    Posts:
    62
    SweatyChair, erkneren and JoNax97 like this.
  26. Slashbot64

    Slashbot64

    Joined:
    Jun 15, 2020
    Posts:
    43
    Does MLAPI even work with the build play domain reload stuff? because Unuty is an absolute snail to enter playmode and iterate with, last thing anyone needs is just another multiplayer framework to have to build things around that also doesn't support built in features that try to improve on the slug editor.
     
  27. luke-unity

    luke-unity

    Unity Technologies

    Joined:
    Sep 30, 2020
    Posts:
    62
    I'm not sure whether MLAPI supports not reloading the domain when entering playmode but I have it enabled in some of my MLAPI projects and it seemed to work fine if I just run MLAPI in host mode in the editor.
     
  28. shininguri

    shininguri

    Joined:
    Nov 25, 2015
    Posts:
    25
    @CreativeChris When you guys get around to making tutorials, could you consider covering save data being implemented with multiplayer & how to tie the two together. Like for for action or rpgs games handling mission and story progression for example. I havent found much info about this around so it would be great to see some professional advice on the topic.
     
  29. CreativeChris

    CreativeChris

    Unity Technologies

    Joined:
    Jun 7, 2010
    Posts:
    383
    Thanks for the feedback - I have recorded your feedback, I know we don't have this covered at the moment, but let me see what we can do to at least have some written tutorial or similar, bare with us.

    If you need immediate help, we welcome you to the Discord Server Support channel.
     
  30. shininguri

    shininguri

    Joined:
    Nov 25, 2015
    Posts:
    25
    Thanks a lot man for considering the request. It means a lot just to see you replying back and doing what you can. Know you guys are already swamped so just want to say I appreciate it.
     
    CreativeChris likes this.
  31. voncarp

    voncarp

    Joined:
    Jan 3, 2012
    Posts:
    187
    Think MLAPI needs some working example scenes with some basic functionality. Ie Start server. Connect to server. Send a message.

    I followed the instructions on the wiki. And I can’t even make a simple client server connection. At least I don’t think I can. It doesn’t seem responsive. Or I’m doing something wrong.

    I’m familiar with most Unity networking libraries dating back to Raknet. I’ve also written my own socket server clients. But, with MLAPI I’m struggling.

    I download the editor installation. I make a GUI to host and connect to server. I select Enet as a transport. And nothing happens. It’s a frustrating experience.

    Has anyone released any projects with MLAPI?
     
  32. CreativeChris

    CreativeChris

    Unity Technologies

    Joined:
    Jun 7, 2010
    Posts:
    383
    Our HelloWorld sample project is being built to do precisely this; it's WIP and not ready yet.

    We are also working on other sample content and educational material. We acknowledge the getting started for MLAPI is somewhat painful, and we are overhauling.

    Please head to our Discord Server for some support; we can help get you on track.
     
    EduardDraude and ScriptsEngineer like this.
  33. Slashbot64

    Slashbot64

    Joined:
    Jun 15, 2020
    Posts:
    43
    Yeah alot more examples both simple ones and and more indepth thanks
     
    CreativeChris likes this.
  34. CreativeChris

    CreativeChris

    Unity Technologies

    Joined:
    Jun 7, 2010
    Posts:
    383
    Let me share more on how we have progressed with regards to learning and examples.

    We are looking at a very simple HelloWorld style example. The first example is literally your very first let's get something connected.

    We are also looking at older example projects and porting those to MLAPI, a 2D Space Shooter, Tanks, and Invaders, we may have two more, so five in total. These examples are the next step in your journey from the HelloWorld beginnings.

    And last but not least, I cannot talk yet about the next thing.

    I think for our first MVP, this is quite extensive, and we have plans to maintain and expand upon what resources will be available for all to learn. We also have plans to accept community contributions - tutorials/video etc.

    Does this sound good? Keep the comments/feedback coming, it is always welcome!
     
    shininguri and JoNax97 like this.
  35. Cranom

    Cranom

    Joined:
    Jan 31, 2018
    Posts:
    17
    A turn-based project exemple would be nice, it gets a fair amount of topic "How to do..." in the forum, plus it's a genre that don't need complexe problem solving needed in real-time gameplay with prediction/reconciliation and such.

    2D space shooter and 3d tanks kind of seems redundant unless one tackles more stuff (like lobby/match list/scene change...) than the other to ease-in the process.

    Does Unity have any product for data persistence, it would be nice to have a project on this subject without having to link to an outside product, because it's also a topic that gets asked a lot and will discourage users if needing to look elsewhere

    And please either have a way to get rid of pretty graphics or have some basic placeholder assets in your projects ! Because having to download multiple Go of data in the beta multiplayer FPS, to be blocked by graphical errors when just a few Ko of information is interesting, was a pain in the a**.

    Maybe don't keep stuff secret, chances are either that it will miss or users won't care...
    Looking forward to those exemple projects, we will see if it is any good when it gets out, execution is all that matter at this point !
     
    dannyalgorithmic likes this.
  36. KokkuHub

    KokkuHub

    Joined:
    Feb 15, 2018
    Posts:
    703
    We picked MLAPI for an ongoing multiplayer project and I can't help say it's not what I was expecting. It's lacking in many ways in usability, and has GC allocations everywhere (NetworkedVar and SyncedVar use tons of boxing). We have had to start modifying it quite a bit from day one to get it to meet our needs. Plus, it has some unsuspecting bugs like this:

    Code (CSharp):
    1.  
    2. public void WriteRangedSingle(float value, float minValue, float maxValue, int bytes)
    3. {
    4.    if (bytes < 1 || bytes > 4) throw new ArgumentOutOfRangeException("Result must occupy between 1 and 4 bytes!");
    5.    if (value < minValue || value > maxValue) throw new ArgumentOutOfRangeException("Given value does not match the given constraints!");
    6.    uint result = (uint)(((value + minValue) / (maxValue + minValue)) * ((0x100 * bytes) - 1));
    7.    for (int i = 0; i < bytes; ++i) sink.WriteByte((byte)(result >> (i << 3)));
    8. }
    9.  
    10. public float ReadRangedSingle(float minValue, float maxValue, int bytes)
    11. {
    12.    if (bytes < 1 || bytes > 4) throw new ArgumentOutOfRangeException("Result must occupy between 1 and 4 bytes!");
    13.    uint read = 0;
    14.    for (int i = 0; i < bytes; ++i) read |= (uint)ReadByte() << (i << 3);
    15.    return (((float)read / ((0x100 * bytes) - 1)) * (minValue + maxValue)) - minValue;
    16. }
    17.  
    18.  
    19.  
    The WriteRanged/ReadRanged are pretty much broken if your minValue is anything other than zero because the way it's used is completely wrong.
     
  37. CreativeChris

    CreativeChris

    Unity Technologies

    Joined:
    Jun 7, 2010
    Posts:
    383
    Can you come to find me on the MLAPI by Unity Discord?
     
    BitziEntertainment likes this.
  38. KokkuHub

    KokkuHub

    Joined:
    Feb 15, 2018
    Posts:
    703
    Sure, which channel/username?
     
  39. CreativeChris

    CreativeChris

    Unity Technologies

    Joined:
    Jun 7, 2010
    Posts:
    383
    We have the #support channel which reaches everyone and on the right-hand-side, you can see profiles that are Unity moderators.
     
unityunity