DarkRift 2 Tutorial for Unity 3D
What is it ?
Reminder : You can find all the DarkRift2 related articles here
You can find the entire project on my official GitHub
DarkRift2 (DR2) is an asset developped by “Darkrift” designed to give to your game a multiplayer dimension very easely.
This is the second version of their product, wich is more fast and reliable than the first one. They took the best from DarkRift and they improved it on DarkRift2.
You can find here the website : https://darkriftnetworking.com/DarkRift2
Dark Rift 2 is a librairy wich allow you to send message through network simply and fastly. It’s an abstraction for sending messages over TCP and UDP. It’s a High Level API. It means that you just have to use classes and functions provided in the library to send message. You don’t need to create you TCP message from scratch !
DR2 is very interresting regarding it’s price. There is 2 version :
- Free : You can use it freely (unlimited users)
- Pro (90$) : This version provides you some extra feature (Matchmaking, Rooms, ..) and you have a complete access to the source code.
DR2 is extremelly well documented. You can fin all the stuff you need here :
How to implements Dark Rift ?
There is two way of implementing DR2 with unity.
- Using the server console (Provided by Dark Rift)
- Using the XML Server Unity Component provided by Dark Rift too…
With the first solution, you’ll need to create your Dark Rift Plugins to handle the server logic. There is a complete exemple on how to create your first plugin with DarkRift.
The second way is to use the XML Server Unity component on a scene, wich means that a scene will act as server.
There is pros and cons for each solution. The main pros for using the XML Server Unity is that this component allows us to us the powerful of the Unity engine (Physics, NavPath, …)
Very simple schema of a Dark Rift 2 communication
Here is a very simplified exemple of Client / Server communication. By using Dark Rift, all that is red surrouded is automaticcaly handled by DR2 without doing anything !
In green, that’s what we have to code with DR2 for sending message (You can either receive message, wich is very similar)
For what a message is supposed to be used ?
Message is information shared by a client and a server (for exemple to login) or by all clients (sharing the player position)
A client never send message to another client. It send message to the server, wich broadcast the message to all clients.
As you understood, message are used to share information between connected clients and server act as the broadcaster
In the next article, we’ll see how to setup the Unity environnement.
Stay tuned !