~/readme

PurrNet - Unity3D

9ed350a5-2701-4163-b19c-89618669479c

PurrNet is our attempt at the purrfect networking solution... It's a 100% free Unity Networking solution with no pro or premium version, and no features locked behind a pay-gate. You can use it to release, and we ask nothing in return! Read the Unique to PurrNet section to see what we offer above other solutions!

Website: https://purrnet.dev/ Docs: https://purrnet.gitbook.io/docs
Docs (source): https://github.com/BlenMiner/PurrNet-Docs

Install

You can install PurrNet through Unity's Package Manager by adding a package through this URL:

https://github.com/PurrNet/PurrNet.git?path=/Assets/PurrNet#release

Or through OpenUM openupm

openupm add dev.purrnet.purrnet

You can also fallback to the asset store but versions will be behind.

Asset store link.

Discord

Discord Banner

Quick Introduction

Transports

  • UDP (reliable and unreliable)
  • WebSockets
  • Steam
  • Local (no socket)
  • PurrTransport (Relay free for development)
  • Composite (Allows multiple transports)

Spawning and Despawning

[SerializedField] GameObject playerPrefab;

private GameObject _player;

void SpawnPlayer()
{
    _player = Instantiate(playerPrefab);
}

void DespawnPlayer()
{
    Destroy(_player);
}

Yes, you are done! PurrNet will handle the rest for you. The best part is that if you want to allow flexibility over security, you can even have clients spawn and despawn their own objects depending on which NetworkRules you pick. With no changes to this code.

Bonus, you can also drag and drop prefabs into the scene and have them spawn automatically. As long as they have a NetworkIdentity component attached to them and are part of your NetworkPrefabs list.

RPCs

You have TargetRPCs, ServerRPCs, and ObserverRPCs. Depending on your network rules, these can all be called by clients too. Or if you want to keep it secure but still allow clients to call some of them, you can use the requireServer: false parameter.

[ServerRPC]
void DoSomethingOnServer()
{
    Debug.Log("Doing something on the server!");
}

Static RPCs are also supported.

[ServerRPC]
static void DoSomethingOnServer()
{
    Debug.Log("Doing something on the server!");
}

Awaitable RPCs are also supported.

[ServerRPC]
static Task<int> GetMyNymber()
{
    return Task.FromResult(42);
}

UnitTask integration is also supported.

[ServerRPC]
static UniTask<int> GetMyNymber()
{
    return UniTask.FromResult(42);
}

Why not Coroutine RPCs? We have that too!

[ServerRPC]
static IEnumerator DoSomethingOnServer()
{
    yield return new WaitForSeconds(1);
    Debug.Log("Doing something on the server!");
}

Generic RPCs are also supported.

[ServerRPC]
static void DoSomethingOnServer<T>(T value)
{
    Debug.Log($"Doing something on the server with {value}!");
}

All of these can be combined. For example, you can have a static RPC that returns a value and is awaitable and generic.

Network Modules

Network Modules are a way to extend PurrNet with your own custom logic. SyncVars are built using Network Modules, and you can create your own Network Modules to add custom logic to your networked objects. This opens up a whole new world of possibilities for modularity and extensibility.

You can also nest these modules inside each other. So for this next example we could have used a SyncVar<int> (another NetworkModule) but for demonstration purposes we won't.

[Serializable]
public class PlayerHealthModule : NetworkModule
{
    [SerializeField] int _health;
    
    [ServerRPC(requireOwnership: true)]
    public void TakeDamage(int damage)
    {
        _health -= damage;
    }
}

The example above shows a simple health module that can be attached to any networked object. Note that any of the mentioned RPCs can be used in Network Modules.

Here is how you would use it:

class SomeIdentity : NetworkIdentity
{
    [SerializeField] PlayerHealthModule _healthModule;
    
    void TakeDamage(int damage)
    {
        _healthModule.TakeDamage(damage);
    }
}

This is just a simple example, but you can create much more complex modules with multiple RPCs and SyncVars. All our built-in features are implemented using Network Modules, so you can be sure that they are powerful and flexible.

Don't forget they can also be generic!

Network Rules

Network Rules are a way to define how your networked objects behave. You can define who can spawn, despawn, and call RPCs on your objects. You can also define who can observe your objects and how they are synchronized. Almost everything is customizable, and every object can have its own set of rules.

image

Serialization

PurrNet uses a custom serialization system that is both fast and flexible. I will keep this short as you shouldn't have to worry about it.

Just want to mention some of the features:

// sending an RPC with an object
// PurrNet will automatically serialize it for you and resolve it's type
[ServerRPC]
void DoSomethingOnServer(object someValue)
{
    Debug.Log($"Doing something on the server with {someValue}!");
}

You can also use the BitPacker directly if you want to send custom data. This avoids creating garbage and is much faster than using the object serialization. It also allows you to send data that might not be able to be represented by a type.

void SendSometing()
{
    using var writer = BitPackerPool.Get();
    
    writer.Write(42);
    writer.Write("Hello, World!");
    
    DoSomethingOnServer(writer);
}

[ServerRPC]
void DoSomethingOnServer(BitPacker data)
{
    int value = default;
    string message = default;
    
    Packer<int>.Read(data, ref value);
    Packer<string>.Read(data, ref message);
    
    Debug.Log($"Doing something on the server with {value} and '{message}'!");
    
    data.Dispose();
}
~/versions

Install via Git URL

Release https://github.com/PurrNet/PurrNet.git?path=/Assets/PurrNet#release
Dev https://github.com/PurrNet/PurrNet.git?path=/Assets/PurrNet#dev

Download Latest

Release 1.19.1
Dev 1.20.0-b.216
Dev 1.20.0-b.215
Dev 1.20.0-b.214
Dev 1.20.0-b.213
Dev 1.20.0-b.212
Dev 1.20.0-b.211
Dev 1.20.0-b.210
Dev 1.20.0-b.209
Dev 1.20.0-b.208
Dev 1.20.0-b.207
Dev 1.20.0-b.206
Dev 1.20.0-b.205
Dev 1.20.0-b.204
Dev 1.20.0-b.203
Dev 1.20.0-b.202
Dev 1.20.0-b.201
Dev 1.20.0-b.200
Dev 1.20.0-b.199
Dev 1.20.0-b.198
Dev 1.20.0-b.197
Dev 1.20.0-b.196
Dev 1.20.0-b.195
Dev 1.20.0-b.194
Dev 1.20.0-b.193
Dev 1.20.0-b.192
Dev 1.20.0-b.191
Dev 1.20.0-b.190
Dev 1.20.0-b.189
Dev 1.20.0-b.188
Dev 1.20.0-b.187
Dev 1.20.0-b.186
Dev 1.20.0-b.185
Dev 1.20.0-b.184
Dev 1.20.0-b.183
Dev 1.20.0-b.182
Dev 1.20.0-b.181
Dev 1.20.0-b.180
Dev 1.20.0-b.179
Dev 1.20.0-b.178
Dev 1.20.0-b.177
Dev 1.20.0-b.176
Dev 1.20.0-b.175
Dev 1.20.0-b.174
Dev 1.20.0-b.173
Dev 1.20.0-b.172
Dev 1.20.0-b.171
Dev 1.20.0-b.170
Dev 1.20.0-b.169
Dev 1.20.0-b.168
Dev 1.20.0-b.167
Dev 1.20.0-b.166
Dev 1.20.0-b.165
Dev 1.20.0-b.164
Dev 1.20.0-b.163
Dev 1.20.0-b.162
Dev 1.20.0-b.161
Dev 1.20.0-b.160
Dev 1.20.0-b.159
Dev 1.20.0-b.158
Dev 1.20.0-b.157
Dev 1.20.0-b.156
Dev 1.20.0-b.155
Dev 1.20.0-b.154
Dev 1.20.0-b.153
Dev 1.20.0-b.152
Dev 1.20.0-b.151
Dev 1.20.0-b.150
Dev 1.20.0-b.149
Dev 1.20.0-b.148
Dev 1.20.0-b.147
Dev 1.20.0-b.146
Dev 1.20.0-b.145
Dev 1.20.0-b.144
Dev 1.20.0-b.143
Dev 1.20.0-b.142
Dev 1.20.0-b.141
Dev 1.20.0-b.140
Dev 1.20.0-b.139
Dev 1.20.0-b.138
Dev 1.20.0-b.137
Dev 1.20.0-b.136
Dev 1.20.0-b.135
Dev 1.20.0-b.134
Dev 1.20.0-b.133
Dev 1.20.0-b.132
Dev 1.20.0-b.131
Dev 1.20.0-b.130
Dev 1.20.0-b.129
Dev 1.20.0-b.128
Dev 1.20.0-b.127
Dev 1.20.0-b.126
Dev 1.20.0-b.125
Dev 1.20.0-b.124
Dev 1.20.0-b.123
Dev 1.20.0-b.122
Dev 1.20.0-b.121
Dev 1.20.0-b.120
Dev 1.20.0-b.119
Dev 1.20.0-b.118
Dev 1.20.0-b.117
Dev 1.20.0-b.116
Dev 1.20.0-b.115
Dev 1.20.0-b.114
Dev 1.20.0-b.113
Dev 1.20.0-b.112
Dev 1.20.0-b.111
Dev 1.20.0-b.110
Dev 1.20.0-b.109
Dev 1.20.0-b.108
Dev 1.20.0-b.107
Dev 1.20.0-b.106
Dev 1.20.0-b.105
Dev 1.20.0-b.104
Dev 1.20.0-b.103
Dev 1.20.0-b.102
Dev 1.20.0-b.101
Dev 1.20.0-b.100
Dev 1.20.0-b.99
Dev 1.20.0-b.98
Dev 1.20.0-b.97
Dev 1.20.0-b.96
Dev 1.20.0-b.95
Dev 1.20.0-b.94
Dev 1.20.0-b.93
Dev 1.20.0-b.92
Dev 1.20.0-b.91
Dev 1.20.0-b.90
Dev 1.20.0-b.89
Dev 1.20.0-b.88
Dev 1.20.0-b.87
Dev 1.20.0-b.86
Dev 1.20.0-b.85
Dev 1.20.0-b.84
Dev 1.20.0-b.83
Dev 1.20.0-b.82
Dev 1.20.0-b.81
Dev 1.20.0-b.80
Dev 1.20.0-b.79
Dev 1.20.0-b.78
Dev 1.20.0-b.77
Dev 1.20.0-b.76
Dev 1.20.0-b.75
Dev 1.20.0-b.74
Dev 1.20.0-b.73
Dev 1.20.0-b.72
Dev 1.20.0-b.71
Dev 1.20.0-b.70
Dev 1.20.0-b.69
Dev 1.20.0-b.68
Dev 1.20.0-b.67
Dev 1.20.0-b.66
Dev 1.20.0-b.65
Dev 1.20.0-b.64
Dev 1.20.0-b.63
Dev 1.20.0-b.62
Dev 1.20.0-b.61
Dev 1.20.0-b.60
Dev 1.20.0-b.59
Dev 1.20.0-b.58
Dev 1.20.0-b.57
Dev 1.20.0-b.56
Dev 1.20.0-b.55
Dev 1.20.0-b.54
Dev 1.20.0-b.53
Dev 1.20.0-b.52
Dev 1.20.0-b.51
Dev 1.20.0-b.50
Dev 1.20.0-b.49
Dev 1.20.0-b.48
Dev 1.20.0-b.47
Dev 1.20.0-b.46
Dev 1.20.0-b.45
Dev 1.20.0-b.44
Dev 1.20.0-b.43
Dev 1.20.0-b.42
Dev 1.20.0-b.41
Dev 1.20.0-b.40
Dev 1.20.0-b.39
Dev 1.20.0-b.38
Dev 1.20.0-b.37
Dev 1.20.0-b.36
Dev 1.20.0-b.35
Dev 1.20.0-b.34
Dev 1.20.0-b.33
Dev 1.20.0-b.32
Dev 1.20.0-b.31
Dev 1.20.0-b.30
Dev 1.20.0-b.29
Dev 1.20.0-b.28
Dev 1.20.0-b.27
Dev 1.20.0-b.26
Dev 1.20.0-b.25
Dev 1.20.0-b.24
Dev 1.20.0-b.23
Dev 1.20.0-b.22
Dev 1.20.0-b.21
Dev 1.20.0-b.20
Dev 1.20.0-b.19
Dev 1.20.0-b.18
Dev 1.20.0-b.17
Dev 1.20.0-b.16
Dev 1.20.0-b.15
Dev 1.20.0-b.14
Dev 1.20.0-b.13
Dev 1.20.0-b.12
Dev 1.20.0-b.11
Dev 1.20.0-b.10
Dev 1.20.0-b.9
Dev 1.20.0-b.8
Dev 1.20.0-b.7
Dev 1.20.0-b.6
Dev 1.20.0-b.5
Dev 1.20.0-b.4
Dev 1.20.0-b.3
Dev 1.20.0-b.2
Dev 1.20.0-b.1
Dev 1.19.2-b.28
Dev 1.19.2-b.27
Dev 1.19.2-b.26
Dev 1.19.2-b.25
Dev 1.19.2-b.24
Dev 1.19.2-b.23
Dev 1.19.2-b.22
Dev 1.19.2-b.21
Dev 1.19.2-b.20
Dev 1.19.2-b.19
Dev 1.19.2-b.18
Dev 1.19.2-b.17
Dev 1.19.2-b.16
Dev 1.19.2-b.15
Dev 1.19.2-b.14
Dev 1.19.2-b.13
Dev 1.19.2-b.12
Dev 1.19.2-b.11
Dev 1.19.2-b.10
Dev 1.19.2-b.9
Dev 1.19.2-b.8
Dev 1.19.2-b.7
Dev 1.19.2-b.6
Dev 1.19.2-b.5
Dev 1.19.2-b.4
Dev 1.19.2-b.3
Dev 1.19.2-b.2
Dev 1.19.2-b.1
Dev 1.19.1-b.11
Dev 1.19.1-b.10
Dev 1.19.1-b.9
Dev 1.19.1-b.8
Dev 1.19.1-b.7
Dev 1.19.1-b.6
Dev 1.19.1-b.5
Dev 1.19.1-b.4
Dev 1.19.1-b.3
Dev 1.19.1-b.2
Dev 1.19.1-b.1
Release 1.19.0
Release 1.18.0
Release 1.17.0