MLAPI - HLAPI Replacement

Hello. I want to tell you about my project called the MLAPI. It’s a high level network abstraction library similar to the HLAPI. It’s designed to offer more features, greater flexibility and performance.

It should have all the feature the HLAPI current has and more. Here are some feature highlights

  • Host support (Client hosts the server)
  • Object and player spawning [Wiki page]
  • Connection approval [Wiki page]
  • Message names
  • Replace the integer QOS with names. When you setup the networking you specify names that are associated with a channel. This makes it easier to manage. You can thus specify that a message should be sent on the “damage” channel which handles all damage related logic and is running on the AllCostDelivery channel.
  • ProtocolVersion to allow making different versions not talk to each other.
  • NetworkedBehaviours does not have to be on the root, it’s simply just a class that implements the send methods etc.
  • Custom tickrate
  • Synced network time
  • Supports separate Unity projects crosstalking
  • Passthrough messages [Wiki page]
  • Scene Management [Wiki page]
  • Built in Lag compensation [Wiki page]
  • NetworkTransform replacement [Wiki page]
  • Targeted messages [Wiki page]
  • Port of NetworkedAnimator [Wiki page]
  • Networked NavMeshAgent [Wiki page]
  • Networked Object Pooling [Wiki page]
  • Synced Vars [Wiki page]
  • Targeted Synced Vars [Wiki page]
  • Encryption [Wiki page]
  • Super efficient BitWriter & BitReader [Wiki page]
  • Command & Rpc system like HLAPI to allow for quick transfer from HLAPI to MLAPI [Wiki page]
  • Observer system similar to the HLAPI [Wiki page]
  • Custom UDP transport support [Wiki page]

Github repo
Binaries
Wiki
API Reference

If you encounter any issues. Please open an issue on Github

Thanks, TwoTen

7 Likes

For those who care, I have created a Wiki on Github. I am starting to get to a point where it’s usable. I will be creating example projects and more wiki pages as the project develops and hopefully it will be ready for use fairly soon. Currently it shares many features with the HLAPI. Such as object spawning, object authority. But it removes the many limitations the HLAPI has (and hopefully their bugs). The fancy features such as an easy way to get variables to sync (syncvars) are still not done. Currently you would have to create it similar to a Cmd - RPC setup. But it is planned.

The wiki can be found here

I have created another repo for Examples. So far the example is just a unity scene with multiplayer where each player controls a cube and the positions sync across the network. It’s simply to show how to write network code with the library and is just very quick and dirty written code.
And btw, the Host feature is not yet working. So use one server and at least one client for now

Hey TwoTen.

Glad to see that you have started working on your project.
But I would like to ask you something. Considering the following code:

https://github.com/TwoTenPvP/MLAPI-Examples/blob/master/Assets/SyncPosition.cs

 private void Update()
    {
        if (!isLocalPlayer)
            return;
        if(Time.time - lastSentTime > (1f / PosUpdatesPerSecond))
        {
            using(MemoryStream stream = new MemoryStream())
            {
                using (BinaryWriter writer = new BinaryWriter(stream))
                {
                    writer.Write(transform.position.x);
                    writer.Write(transform.position.y);
                    writer.Write(transform.position.z);
                }
                SendToServer("PositionUpdate", "PositionUpdates", stream.ToArray());
            }
            lastSentTime = Time.time;
        }
        transform.Translate(new Vector3(Input.GetAxis("Horizontal") * Time.deltaTime, Input.GetAxis("Vertical") * Time.deltaTime, 0));
    }

The code above won’t send "PosUpdatesPerSecond"n packets to the server at the fixed tickrate of “PosUpdatesPerSecond” if the Client’s FrameRate would be lower than the “PosUpdatesPerSecond” value.

Let’s assume that your tickrate is 64, which means that the Client sends PositionUpdate 64 times per second. This particular case would work only if the Client’s FPS is 64 or higher, if you will try to change it to the lower value on the client by “Application.targetFrameRate = 20” - you will see jittering on the server because the client would send only 20 packets per second instead of 64.

So what I would suggest, is to somehow process that SendToServer in a new thread, because your main thread would be always busy and limited to the GPU resources.

But in general, I like the idea of MLAPI, sounds cool. Keep it up :wink:
By the way, what happened to your blog?

Hello.
I am currently on vacation in japan and this is a sideproject I started (though I am planning to continue it). As for the example project. You are correct. The example is just to show the basics of how to get started with message sending.

That out the way, you are corect. You have a good point though. I could add a thread system. So that once the send function is called, we send the byte array off to the thread to be processed. And its only returned to the main thread when it’s ready to be passed to the LLAPI. Same for receive but in reverse.

Not sure if it’s worth it though. The only gain would be that the binary serialization would happend on a separate thread. The HLAPI works on one thread aswell similar to this. Dont think you would get much of a benefit since game logic has to happend on the main thread and the NetworkTransport can also just be interacted with from that thread

As for the blog. Moved the articles to twotenpvp.github.io

1 Like

Well, probably you are right. It might not be worth it.

https://github.com/TwoTenPvP/MLAPI/blob/master/MLAPI/MonoBehaviours/Prototyping/NetworkedTransform.cs
Here is a better NetworkTransform I wrote that shows some new features I added to the MLAPI. It currently just syncs transforms and does interpolation based on the sendrate. But it illustrates how to use the MLAPI fairly well.

Mainly it shows the new Target variant of the send methods. Using the Target version means that only listeners registered on the same NetworkedObject as it’s being sent from will be Invoked. Worth noting is that if multiple listeners are registered to the same NetworkedObject they will all be invoked. Even if they are on different NetworkedBehaviours. This is in order to not have to sync the NetworkedBehaviours themselves.

If anyone has any questions about the MLAPI. Feel free to ask. Currently, I feel that it’s at a point where it can be a better alternative to the HLAPI. I just need to consider Variable sync and scene management.

Also, if you encounter any problems with the library. Please open an Issue on Github.

I have added a big new feature. MessagePassthrough. It allows messages to be sent from Client to Client via the Server. This is similar to a Command → RPC Setup but requires a single call. Security features are implemented. You have to manually mark MessageTypes to be used for Passthrough and the Server will also inject the Source ClientId when passing it to the target. I have added a Wiki page for it.

Lot’s of new features have been added. Complete feature list can be found on the GitHub readme. It should now pretty much be production ready and I’m happy to hear from anyone using it. Any issues and/or missing features you encouter, please report them on GitHub and they will be looked into.

The components have replacements now (NetworkedTransform & NetworkedAnimator).

Have you considered adding a NetworkedNavMeshAgent component to sync velocity and other NavMeshAgent data from server to clients?

I’ll make sure to get that done!

My thought was that it would be an alternate to NetworkedTransform, and include transform updates at a much lower frequency, allowing the clients to largely solve and run the agents independently. The big picture would be that the clients would have code that would drive other things off the NavMeshAgent that the server wouldn’t have because such would be non-critical to game play or precision across all clients, e.g. the destination is more important than the journey. If properties were sent as reliable only when changed, the data traffic would be a lot less for such entities. One scenario might be to have the server raise or lower the transform update frequency based on distance from client character for such agents. Come to think of it that might be a nice optimization for NetworkedTransform as well when proximity checking is active.

It’s been added.
https://github.com/TwoTenPvP/MLAPI/blob/master/MLAPI/MonoBehaviours/Prototyping/NetworkedNavMeshAgent.cs

As for the Distance & Proximity thing, i’ll get that sorted. For future feature request. Please use the Issue feature on GitHub. Makes it super neat for me to track. That’s where pretty much all feature requests have been put so far and almost all have been implemented.

1 Like

Hello. I can’t figure out how to launch it.
I downloaded MLAPI-Examples-master.zip
But there is missing component on GameObject.

Right, I think that’s due to the import order of the components. Idk why Unity does that tbh.

NetworkManager has a NetworkingManager component, the player object just has NetworkedObject, NetworkedTransform and NetworkedAnimator that is from the library.

1 Like

@TwoTen You might want to update your readme and wiki that you support Websockets / WebGL and document it.

The documentation, API reference and wiki are documenting the last release. Thus they are a bit outdated. I am currently working on version 1.0 thus there has been no release for a bit. We are getting a brand new serializer in that uses bits instead of bytes to save as much space as possible & lots of new features. A new Editor script that lets you handle your versions and update the MLAPI in the engine.

Here is a peek
https://i.imgur.com/RuW71Z4.png

In case you didn’t see this…

Yes, i was the one who asked for it to be released as I need it for UDP hole punch, relay and some other things

I’ve just released version 1.0. It offers lot’s of new features and fixes and is now ready for use (IMO). It has a nice way to manage your MLAPI version to prevent your project from breaking while at the same time letting you easily upgrade. Please do excuse my horrible Editor scripting skills.

1 Like