Getting started
Quickstart: Unity
Connect a Unity project to SyncVerse Cloud and get two players into one room.
Before you start
- Unity 2021.3 LTS or newer.
- A SyncVerse Cloud account and a project. Sign in, create a project, and copy its App ID (it starts with
sv_app_).
Install the package
In Unity open Window › Package Manager, choose Add package from git URL and paste the package URL.
https://github.com/simple-yet-efficient/syncverse-unity.git#v0.2.0The #v0.2.0 suffix pins the release; drop it to follow the latest code. Newtonsoft JSON is installed with the package. Example scenes are in syncverse-samples.
Add your App ID
- Open SyncVerse › Cloud Setup. It creates the settings asset if there is none.
- Paste the App ID and set Mode to Cloud. Check that Cloud URL is
wss://syncverse.aqaddoura.com. - Press Test connection. It reports the server's welcome, or the reason a connection was refused.
You can also create the asset with Assets › Create › SyncVerse › Settings. It must be named SyncVerseSettings and live in a Resources folder, because the SDK loads it from there.
Make a networked prefab
- Create a prefab named
PlayerunderAssets/Resources/. - Add SyncVerseView and SyncTransform to it.
- In your movement script, only read input when
GetComponent<SyncVerseView>().IsMineis true.
Connect, join and spawn
Add this component to an object in your scene and press Play.
using SyncVerse;
using UnityEngine;
public class QuickStart : MonoBehaviour {
readonly SyncVerseMaster master = new SyncVerseMaster ();
SyncVerseRoom room;
void Start () {
master.OnConnectFailed += reason => Debug.LogError ("SyncVerse: " + reason);
master.OnConnected += () =>
// Creates "my-room", or returns the existing one so you join it.
master.CreateRoom ("my-room", new RoomOptions { MaxPlayers = 8 }, res => {
if (res.Room == null) { Debug.LogError ("Create failed: " + res.Status); return; }
room = master.ConnectToRoom (res.Room);
room.OnConnected += () => room.Join ("Player" + Random.Range (1, 1000));
room.OnJoined += () => room.Instantiate ("Player", Vector3.zero, Quaternion.identity);
});
master.Connect (); // no URL: uses the SyncVerseSettings asset
}
}Build the game, or open a second editor with the same project, and press Play again. Both players end up in my-room and see each other move. The dashboard's Rooms page shows the room and both players.
Next steps
- Rooms and the lobby: room lists, properties, the master client.
- Networked objects: ownership and syncing your own components.
- RPCs: calling methods on every client.