isOwnedLocallySelf during Start()
I've made a script for setting and syncing a unique ID for my objects; I am generating the UUID and setting it to the model during the Start() function here:
but according to my logs both clients end up calling GenerateAndSetNewUuid()? Is it possible that both clients think they own the object during the Start method? What would be a workaround to this to make sure only one clients tries to set the Uuid and ensures the other clients try to Update the UUID once the first client sets it?
7 Replies
Hi @Marlon Stein. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Yes, it is possible that both clients think they own the object during the Start method. According to the documentation (https://normcore.io/documentation/reference/classes/Normal.Realtime.RealtimeView), accessing the
realtimeView
property before Start is unreliable. This means that the isOwnedLocallySelf
property might not return the correct value during the Start method.
A possible workaround could be to delay the ownership check until after the Start method has completed. You could use a coroutine to achieve this. Here's an example:
This will ensure that the realtimeView
property has been properly initialized before you check the isOwnedLocallySelf
property.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@1140565356239405076> kapa.ai is still learning and improving, please let us know how it did by reacting below
Hm okay. I don't think your fix is good, but if the property is infact unreliable that's a start.
I normally check if the client is connected to the room before doing anything Normcore related - which usually takes a couple of seconds atleast.
These are Prefabs that only get instantiated once everyone is definitely connected so it shouldn't be something like that?
Ahh okay nvm then
you can try isFreshModel instead in OnModelReplaced event
isFreshModel is only true on the instantiating client and the model data will go out with the instantiate packet