First person to create the room fails to listen to the on change events correctly
If the room is initially empty and the player creates it, the onChange events don’t trigger correctly — the value updates, but onChange doesn’t run when the other player changes it.
17 Replies
Hi @gubebra. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
This issue with onChange events not triggering correctly for the first person who creates a room is likely related to how Normcore handles model updates and change events.
When examining the knowledge sources, I can see a few potential causes for this behavior:
1. Model Ownership Issues: When a client owns a model, only that client can make changes to it. If the first player automatically becomes the owner of models in the room, other players' changes might be rejected by the server.
As mentioned in the Ownership and Lifetime Flags documentation:
When a model is owned by a client, the server only lets the owning client make changes to it or to any of its child models.2. Instant Updates Behavior: The datastore applies updates immediately for the local client, but server rejections can cause rollbacks. From the Datastore documentation:
It is possible that the server will reject an update due to either ownership or Normcore Private plug-ins. When this happens, the server sends back the rejected update or a modified version of the state in the update.3. RealtimeComponent Setup: If your custom RealtimeComponent isn't properly registered with a RealtimeView, the onChange events might not fire correctly. As noted in the Synchronizing Custom Data FAQ:
You have most likely added your custom component to a game object before it was converted to a RealtimeComponent subclass.To fix this issue, try these solutions: 1. Make sure your models that need to be modified by multiple clients are unowned (ownerID = -1) or have their ownership properly managed. 2. Verify that your RealtimeComponents are properly registered with RealtimeViews. 3. Check your implementation of the
OnRealtimeModelReplaced
method to ensure you're properly subscribing to change events.
Here's an example of properly subscribing to change events in a RealtimeComponent:
If these solutions don't resolve your issue, you might need to examine your specific implementation more closely or reach out to the Normcore team for further assistance.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@599054560270483456> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
@Normcore Assistant the value clearly updates if I log it, but the onChange fails. If the user rejoins it works again
Let me check the knowledge base for you again. One moment! :books:
----------------------
Based on your additional information that the value updates (visible when logging) but the onChange event doesn't fire, and that rejoining the room fixes the issue, this points to a specific problem with event registration in Normcore.
This behavior is likely related to how Normcore handles model updates and change events during the initial room creation. Let's look at some possible causes:
1. Delta Updates Timing: Normcore sends updates at a specific rate (default 20Hz) and groups them into packets. When model updates are applied, they're applied one at a time, and change events fire for each value.
As mentioned in the Room Common Questions documentation:
When model updates are applied, they're applied one at a time, and a change event fires for that value. However, it's possible the other values from that packet hadn't yet been applied.2. Event Registration Timing: The issue might be that the first person to create the room is registering for change events at a time when the model isn't fully initialized or connected to the datastore. 3. RealtimeCallback: For cases where you need to ensure all updates have been applied, Normcore recommends using RealtimeCallback instead of relying solely on individual change events. Since rejoining the room fixes the issue, this suggests that the problem is related to the initial setup and event registration when the room is first created. To fix this issue, try these approaches: 1. Make sure you're registering for change events after the model is fully initialized and connected to the datastore. This might mean waiting for
realtime.connected == true
or the didConnectToRoom
event.
2. Consider using RealtimeCallback to get an event that fires once all updates have been applied to a model, rather than relying on individual property change events.
3. In your OnRealtimeModelReplaced
method, ensure you're properly unsubscribing from the previous model's events and subscribing to the new model's events.
4. Check if you're properly handling the case where the model might be null during initialization.
If these solutions don't resolve your issue, you might need to examine your specific implementation more closely or reach out to the Normcore team through their Discord community for further assistance.
Let me know if you need more specific guidance based on your implementation!
Room Common Questions
Datastore
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@599054560270483456> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
maybe you registered to an old model that got replaced, the bot's code should account for that though
I'm trying to make a blank project and see if it's happening
But I'm using a very similar code from the bot
Only happens with RealtimeDictionary... I can send the blank project in a few
@Normal Team sorry for the ping... do you guys think there's a chance this might be a bug?
I have tried subscribing to the change event on didConnectToRoom like the bot suggested but that didn't help
Hey, thanks for the repro. I'll look into it 👍
Thanks Mark, let me know if you need anything else from me
I've confirmed the issue on our side. We have a fix in mind that we'll release in the next 3 weeks.
You're right, it affects RealtimeDictionary elements (and maybe elements in other types of collections) specifically when the model is created before the room is created (such as
OnRealtimeModelReplaced
when isFreshModel = true
).That's great, I'm glad you guys found it. Can you let me know when it's fixed?
For now, do you know any work around?
We’ve done some digging and it seems there isn’t an easy work around to get change events to fire again. I’ll make sure we ping you when the patch release goes out. In the meantime, your best bet is to check for changes in Update() on your Realtime component or potentially downgrade to v2.13.2
Thank you
Following up here too. This has been fixed in v2.15.3: https://discord.com/channels/393839515074297858/852911447784947723/1365073685215711232
Let us know how it works out for you!