Skip to content
PEERLESSDocs

Unity

Build for Unity Web and use the PeerlessBridge component for relay rooms.

Build settings

  1. Switch the platform to Web.
  2. In Publishing Settings, set Compression Format to Disabled. Compressed .gz, .br and .unityweb files are not accepted.
  3. Build, then ZIP the output with index.html at the root, including Build/*.loader.js, *.framework.js, *.wasm, *.data and TemplateData.

A single-player Unity game needs nothing else.

Relay rooms with PeerlessBridge

The Unity integration contains Assets/PeerlessBridge.cs, Assets/Plugins/WebGL/Peerless.jslib and peerless-unity.js.

  1. Copy both assets into your project and attach one PeerlessBridge to an active GameObject with a unique, stable name.
  2. Copy peerless-sdk.js and peerless-unity.js beside the exported index.html and load them before the Unity loader:
index.html
<script src="peerless-sdk.js"></script>
<script src="peerless-unity.js"></script>
  1. Subscribe to the bridge before Start and send events after you receive joined:
RoomClient.cs
public class RoomClient : MonoBehaviour
{
    public PeerlessBridge bridge;

    void Awake()
    {
        bridge.Message += json => Debug.Log(json); // ready, joined, presence, event, disconnect, error
    }

    public void Move(float x, float y)
    {
        bridge.SendEvent("{\"name\":\"move\",\"data\":{\"x\":" + x + ",\"y\":" + y + "}}");
    }
}

Each message is a JSON envelope with type and data. A solo launch reports ready with room: null and opens no socket. Destroying the component leaves the room.

Upload settings

Choose Unity Web and keep index.html as the entrypoint. Enable Peerless rooms only when you include the bridge.