PurrNet
PurrNet is a free networking framework for Unity by Pebbles Games Consultancy Corporation, Riten SARL available under the MIT license.
Getting Started
Automatic Installation
To automatically install PurrNet, Git must be installed on your machine. After installing Git, you may need to restart Unity before continuing with the automatic installation.
With Git installed, from the top menu, go to Tools > Kaiju Solutions > Multiplayer Engine > Integrations > Install > PurrNet. If you have other networking libraries installed, it will prompt you to ask if you wish to uninstall them. It is recommended to do this to ensure conflicts do not happen. Once installed, if you have any other networking integrations in the project, you will also be prompted to remove them. This is also recommended to ensure you do not accidentally use the wrong components from the other networking integrations.
Manual Installation
If you choose not to install Git, you can still install PurrNet manually by getting the latest .unitypackage from GitHub or downloading it from the Unity Asset Store.
Components
The integration is composed of two components, being a transport for sending data over the network and a component to synchronize users over the network.
Transport
The KaijuTransport component is the core of the integration. To use it, assign it to your PurrNet NetworkManager. You do not need to access most properties or methods manually on the KaijuTransport, but there are a few which are relevant:
KaijuTransport.Channel- The main channel over which information is sent.KaijuTransport.Lifetime- A secondary channel over which networking handshaking is performed.KaijuTransport.autoConnect- If you wish to automatically start PurrNet when joining a lobby. For most simple use cases, you will want to keep this enabled. However, if you are interested in creating a pre-match character selection or group matchmaking screen, you may consider turning this off. If turned off, you will need to later callKaijuTransport.Connect()once ready in the lobby to start PurrNet.KaijuTransport.autoDisconnect- Determines if the client should leave the lobby when PurrNet shuts down. If you wish to implement custom host migration, turn this off.
Host Migration
PurrNet does not support host migration out of the box. However, KMPE gives you a means to implement your own custom host migration. First, disable KaijuTransport.autoDisconnect. Then, listen for the KaijuTransport.OnStopping callback. When triggered, you should serialize all information needed for migration to continue the game. Then, if you are the new owner which can be checked by MultiplayerManager.IsOwner, call KaijuTransport.Connect() to start a new game, and load all the serialized information. Lastly, indicate to other members in the lobby that the migrated game is ready, and they will then call KaijuTransport.Connect() themselves. If the members also need to load any serialized migration data, they can then do so.
User Link
The KaijuUserLink component provides an easy means to synchronize Kaiju Users with the network identifiers they are assigned by PurrNet. In most use cases, you will want to attach a KaijuUserLink component to your player prefab, and KMPE will handle the synchronization with a KaijuUser component allowing you to easily access the user's name and icon. For more on the KaijuUser component and getting user information, see the users documentation. If you wish to access the synchronized identifiers outside of the KaijuUserLink component, you can use the KaijuTransport.SteamToPurrNet(ulong) and KaijuTransport.PurrNetToSteam(int) methods.
Sample
To access the sample, open the package manager window by going to Window > Package Management > Package Manager. In the In Project tab, click on Kaiju Multiplayer Engine and click the Samples tab. First, import the Common sample followed by the PurrNet sample. Then, from the top menu, go to Tools > Kaiju Solutions > Multiplayer Engine > Samples > PurrNet to generate the sample scene.
Resources
- Official documentation.
- The Bobsi Tutorials YouTube channel; a creator of PurrNet.
- Their overview video is a great place to start.
Testing
To test your game's multiplayer functionality locally, check out the testing documentation.