Is didConnectToRoom realtime different from the original?
In this example:
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!");
}
}
}
There is _realtime and then in DidConnectToRoom realtime. Why are these different? I am logging both and they give different room.name results...4 Replies
Hi @khoi. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
The
didConnectToRoom
event in Normcore passes the specific Realtime instance that triggered the event as a parameter to your callback function. This is by design and is part of the standard Realtime API.
In your example:
The realtime
parameter in the callback is the Realtime instance that fired the event. This is the same instance as _realtime
in your class (the serialized field), assuming you're only using one Realtime instance in your scene.
If you're seeing different room.name
results when logging both _realtime.room.name
and realtime.room.name
, there are a few possible explanations:
1. You might have multiple Realtime instances in your scene, and the event is firing from a different instance than the one you've assigned to _realtime
.
2. The timing of when you're logging the values might be different. The didConnectToRoom
event fires specifically when Realtime has successfully connected to a room and all realtime prefabs and views in the scene have been connected to the datastore, as documented in the Realtime reference.
3. If you're connecting to multiple rooms in sequence with the same Realtime instance, you might be seeing different room names at different points in your code execution.
To debug this issue, I would recommend:
- Verify you only have one Realtime instance in your scene
- Check when exactly you're logging the values
- Make sure you're not disconnecting and reconnecting to different rooms
The Realtime API is designed to support multiple instances, which is why the event provides the specific instance that triggered it as a parameter.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@412870643533479936> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
Hmmm, idk, none of these cases are what I'm experiencing so I wonder if this is a bug. I'll get a repro later if I have time.
hmm they should never be different
would love a repro if you’ve got it