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 for Steam > Dependencies > 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 SteamTransport
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 SteamTransport
, but there are a few which are relevant:
SteamTransport.Channel
- The main channel over which information is sent.SteamTransport.Lifetime
- A secondary channel over which networking handshaking is performed.SteamTransport.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 callSteamTransport.Connect()
once ready in the lobby to start PurrNet.SteamTransport.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, MPE4S gives you a means to implement your own custom host migration. First, disable SteamTransport.autoDisconnect
. Then, listen for the SteamTransport.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 SteamManager.IsOwner
, call SteamTransport.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 SteamTransport.Connect()
themselves. If the members also need to load any serialized migration data, they can then do so.
User Link
The SteamUserLink
component provides an easy means to synchronize Steam users with the network identifiers they are assigned by PurrNet. In most use cases, you will want to attach a SteamUserLink
component to your player prefab, and MPE4S will handle the synchronization with a SteamUser
component allowing you to easily access the user's name and icon. For more on the SteamUser
component and getting user information, see the users documentation. If you wish to access the synchronized identifiers outside of the SteamUserLink
component, you can use the SteamTransport.SteamToPurrNet(ulong)
and SteamTransport.PurrNetToSteam(int)
methods.
Sample
After installing PurrNet, a basic sample will be created at Assets > KaijuSolutions > SteamMultiplayerEngine > PurrNet > Samples > Multiplayer Engine for Steam - PurrNet
. This sample demonstrates how to utilize the transport and user link components. In this sample, control your player using WASD or the arrow keys. If the sample was not automatically created, you can manually generate it by clicking Tools > Kaiju Solutions > Multiplayer Engine for Steam > Dependencies > PurrNet Sample
from the top menu, unless you have already removed all sample scripts from the project in which case you will need to reinstall MPE4S to get the sample back.
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.