Call DidChange event when value is the same
I basically want to trigger the ValueDidChange every time I assign model.value to something, even if that value is the same as before.
For some context, I'm sending a string to all clients when a player scores and if he scores again the string is going to be the same, but I need the StringDidChange event to trigger on all clients to display who scored.
26 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:
----------------------
In NormalVR, the
ValueDidChange
event is triggered when a value changes. If you're setting the same value again, the event might not be triggered because the value hasn't technically changed.
One workaround could be to slightly modify the value each time you set it, even if the meaningful content remains the same. For example, you could append a unique, but irrelevant, character or number to the string each time a player scores. This would ensure that the ValueDidChange
event is triggered each time, as the value is technically different each time.
Here's an example of how you might implement this in your code:
In this example, a new GUID is appended to the player name each time they score. This ensures that the value is unique each time, triggering the ValueDidChange
event. You can then handle this event and strip the appended GUID before displaying the player name.
Remember to handle the ValueDidChange
event properly in your code. Here's an example of how you might do this:
In this example, the ValueDidChange
method splits the value on the underscore character (_
), and takes the first part as the player name. It then calls a hypothetical DisplayPlayerScored
method to display the player name.
Please note that this is a workaround and might not be the best solution depending on your specific use case. Always consider the implications of your design decisions and choose the best solution for your needs.
For more information on how to use ValueDidChange
and other events in NormalVR, you can refer to the official documentation (https://normcore.io/documentation/realtime/synchronizing-custom-data#creating-a-realtimecomponent-subclass).
----------------------
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 us know how it did by reacting below
the bot doesn't know but there's a better option
set the equality check parameter to false when you make the model
it's not in the docs but was added recently
Interesting, when defining the RealtimeProperty?
yeah, use intelisense in your IDE to get the property name
RealtimePropertyAttribute(uint propertyID, bool reliable, bool createDidChangeEvent = false, bool includeEqualityCheck = true)
set the last one to false
Like this?
yeah
It's almost working, I get the event fired for the person that changed the string but not the other clients
make sure they have registered to the event before you change it
I don't know if I've done something wrong it's a really simple script:
you probably want to check the value on model replaced in case it's already set when you join
Still not working. I'm changing the model value here a lot of times and no luck. Do you now which version of Nomcore has this feature?
2.9.3
Yeah I have version 2.10.4
Is that expected behaviour? Because the event is called for the person that changed the variable.
no, it should call the event
Should I file a bug then?
could do, as an alternative you can add an int property that you increment when you want to fire an event
did you make a new build for all clients after updating normcore and enabling this flag?
Yes, I actually have 2 editors open with the project
if you're able to make a repro in a blank project, I'd love to take a look
I'll try
@Max I managed to repro on a blank project, here's the video
Here're the project files
@NormalMark want to take a look at this when you get a sec?
Hey, thanks for putting this test project together! We identified the issue and we're working on a fix 👍
Great to hear thanks!