RealtimeComponent connected
how do I know when a RealtimeComponent is initialized and connected to the network?
2 Replies
Hi @Ryan Green | MONA. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
A
RealtimeComponent
is initialized and connected to the network when the Realtime
instance it is associated with is connected. You can check this by using the connected
property of the Realtime
instance. This property returns true
if the Realtime
instance is connected and its views are initialized.
Here is an example of how you can check this:
In addition, the Realtime
class provides an event didConnectToRoom
that is fired when Realtime
is connected to a room and all realtime prefabs and realtime views in the scene have been successfully connected to the datastore. You can subscribe to this event to get notified when the connection is established.
Here is an example of how you can use this event:
Remember that if you're dealing with a RealtimeView
that exists in a scene file, you'll need to wait until realtime.connected == true
, or the didConnectToRoom
event has fired. RealtimeView
uses Start()
internally to register with Realtime
, and it’s possible your start method ran before RealtimeView.Start()
.
Sources:
- Realtime Properties (https://normcore.io/documentation/reference/classes/Normal.Realtime.Realtime)
- Realtime Events (https://normcore.io/documentation/reference/classes/Normal.Realtime.Realtime)
- Common Questions (https://normcore.io/documentation/realtime/common-questions#why-do-i-get-the-error-this-view-doesnt-have-a-model-yet-wait-until-the-model-is-present-before-interacting-with-the-ownership-when-interacting-with-realtimeview)
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@337874773742845953> kapa.ai is still learning and improving, please let us know how it did by reacting below