https://github.com/tik-choco-lab/mistnet
UnityWebRTC: A decentralized networking library for Unity, leveraging WebRTC for serverless, real-time communication in multiplayer games and metaverse applications.
https://github.com/tik-choco-lab/mistnet
csharp distributed unity webrtc
Last synced: 5 months ago
JSON representation
UnityWebRTC: A decentralized networking library for Unity, leveraging WebRTC for serverless, real-time communication in multiplayer games and metaverse applications.
- Host: GitHub
- URL: https://github.com/tik-choco-lab/mistnet
- Owner: tik-choco-lab
- License: mit
- Created: 2023-12-13T00:28:03.000Z (over 2 years ago)
- Default Branch: develop
- Last Pushed: 2026-01-13T07:27:34.000Z (5 months ago)
- Last Synced: 2026-01-13T07:49:59.219Z (5 months ago)
- Topics: csharp, distributed, unity, webrtc
- Language: C#
- Homepage:
- Size: 2.87 MB
- Stars: 31
- Watchers: 0
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# MistNet


[](https://github.com/tik-choco-lab/mistnet/releases)
[](https://deepwiki.com/tik-choco-lab/mistnet)
[](README_JP.md)
[](README_CN.md)
# Features
A fully decentralized network library for Unity based on WebRTC.
It uses a signaling server only for the initial connection establishment, and thereafter realizes multiplayer communication basically without a server. A TURN server can also be used if necessary.
**Implementation example**
https://github.com/tik-choco-lab/mistnet/assets/38463346/cd4a1d95-3422-4b07-b9b6-21f8c63cd1f8
# Setup
1. Install [NuGetForUnity](https://github.com/GlitchEnzo/NuGetForUnity) and search/install **MemoryPack**.
2. Install [MemoryPack](https://github.com/Cysharp/MemoryPack) via Git URL:
```
https://github.com/Cysharp/MemoryPack.git?path=src/MemoryPack.Unity/Assets/MemoryPack.Unity
```
3. Install [UniTask](https://github.com/Cysharp/UniTask) via Git URL:
```
https://github.com/Cysharp/UniTask.git?path=src/UniTask/Assets/Plugins/UniTask
```
4. Install **MistNet** via Git URL:
```
https://github.com/tik-choco-lab/mistnet.git?path=/Assets/MistNet
```
# Quickstart



## Signaling Server
When you run first, a config file will be generated.
Open mistnet_config.json
and set the signaling server URL.
```json
"bootstraps": [
"wss://rtc.tik-choco.com/signaling"
],
```
If you want to use your own signaling server, please refer to the following repository.
https://github.com/tik-choco-lab/mistnet-signaling
# Usage
Place the "MistNet" Prefab in the Scene.
The Prefab is located in "Packages/MistNet/Runtime/Prefabs".

Please configure the connection selection method as shown in the image.
Set it to Default if you want to connect in a full mesh.

# Setting up GameObjects to Synchronize
## Configuration
- Add "MistSyncObject" component.
- Used for RPC calls and identifying the object to sync.
## Position Synchronization Method
- Add "MistTransform" component.
## Animation Synchronization Method
- Add "MistAnimatorState" component.
## Player Instantiation
- Instead of placing the GameObject to synchronize in the Scene from the beginning, you need to Instantiate it via MistNet.
- Register the target GameObject's Prefab in Addressable Assets and execute as follows:

```csharp
[SerializeField]
string prefabAddress = "Assets/Prefab/MistNet/MistPlayerTest.prefab";
MistManager.I.InstantiateAsync(prefabAddress, position, Quaternion.identity).Forget();
```
# RPC
## Registration Method
Add `[MistRpc]` before the method.
```csharp
[MistRpc]
void RPC_○○ () {}
```
## Invocation Method
```csharp
[SerializeField] MistSyncObject syncObject;
// Method to send to everyone including self
syncObject.RPCAll(nameof(RPC_○○), args);
// Method to send to all connected Peers
syncObject.RPCOther(nameof(RPC_○○), args);
// Method to execute by specifying the destination ID
syncObject.RPC(id, nameof(RPC_○○), args);
```
# Variable Synchronization
By adding `[MistSync]`, you can synchronize variables.
```csharp
[MistSync]
int hp { get; set; }
```
Synchronization occurs automatically when a user joins for the first time and when the value changes.
Also, you can execute an arbitrary method during synchronization.
```csharp
[MistSync(OnChanged = nameof(OnChanged))]
int hp { get; set; }
void OnChanged();
```