RoyNexus
RoyNexus11h ago

Toggle on/off network connectivity

Is there an easy config to toggle on/off connectivity to mock offline/online transitions on editor?
4 Replies
kapa.ai
kapa.ai11h ago
Hi @RoyNexus. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Yes, Normcore provides an easy way to toggle between online and offline modes, which can be useful for mocking offline/online transitions in the Unity editor. This is done through the "Offline Mode" feature. Here's how you can implement it: 1. First, make sure to uncheck "Join Room on Start" on the Realtime component in the Unity inspector if you're going to manually call Connect(). 2. Then, you can use the ConnectOptions struct when calling Connect() on your Realtime instance. The offlineMode boolean in this struct allows you to toggle between online and offline modes. Here's an example of how to implement this:
class OfflineModeExample {
[SerializeField]
private Realtime _realtime;

private void Start() {
// Notify us when Realtime successfully connects to the room
_realtime.didConnectToRoom += DidConnectToRoom;

// Connect to "My Room" in offline mode
_realtime.Connect("My Room", new Room.ConnectOptions {
offlineMode = true
});
}

private void DidConnectToRoom(Realtime realtime) {
if (realtime.room.offlineMode) {
Debug.Log($"Connected to room in offline mode!");
}
}
}
class OfflineModeExample {
[SerializeField]
private Realtime _realtime;

private void Start() {
// Notify us when Realtime successfully connects to the room
_realtime.didConnectToRoom += DidConnectToRoom;

// Connect to "My Room" in offline mode
_realtime.Connect("My Room", new Room.ConnectOptions {
offlineMode = true
});
}

private void DidConnectToRoom(Realtime realtime) {
if (realtime.room.offlineMode) {
Debug.Log($"Connected to room in offline mode!");
}
}
}
You can easily toggle between online and offline modes by changing the offlineMode boolean in the ConnectOptions. It's important to note that in offline mode, some behaviors are different: - Realtime.clientID and Room.clientID will always return 0. - Realtime.roomTime and Room.time will return the device's system time. - The datastore state of an offline room is cleared upon calling Disconnect(). For more details on offline mode and its limitations, you can refer to the Room > Offline Mode documentation. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai11h ago
<@362795742198235136> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
RoyNexus
RoyNexusOP11h ago
I'm aware of that option, but I was thinking more towards simulating a lost network connection while playing online
Mechabit
Mechabit10h ago
if you're on quest you can just take your headset off for a minute and you'll get timed out by the server

Did you find this page helpful?