cryptomax
cryptomax3mo ago

Prevent ownership takeover isn't designed to be used dynamically during time correct?

If we have a rigidbody that multiple poeple may be touching but we dont want realtime transform to automatically transfer ownership of.
9 Replies
kapa.ai
kapa.ai3mo ago
Hi @cryptomax. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Yes, you're correct. The preventOwnershipTakeover flag is designed to control the ownership of a RealtimeView at runtime. When this flag is set to true, the server will deny any client’s attempt to change the ownership of an object in that model unless it has no owner. This means that if you have a rigidbody that multiple people may be touching but you don't want RealtimeTransform to automatically transfer ownership of, you can set this flag to true to prevent the ownership takeover [source (https://normcore.io/documentation/room/ownership-and-lifetime-flags#prevent-ownership-takeover-of-a-realtimeview)]. However, if you're using a Rigidbody with RealtimeTransform, the RealtimeTransform will automatically clear the owner when the object comes to rest. If you want to avoid this behavior, you can use the maintainOwnershipWhileSleeping property. If set to true, the RealtimeTransform will continue to be owned by the local client when the attached rigidbody goes to sleep. This will prevent other clients from taking over the simulation for this object [source (https://normcore.io/documentation/reference/classes/Normal.Realtime.RealtimeTransform)]. In the case of a player character, for example, you would want to set maintainOwnershipWhileSleeping to true to ensure that the player always retains control over their character, even when it is not moving [source (https://normcore.io/documentation/guides/creating-a-player-controller#making-it-multiplayer)]. Remember, if you want to move an object, you need to request ownership of it. This is done by calling RequestOwnership() on the RealtimeTransform [source (https://normcore.io/documentation/realtime/networked-physics#ownership--physics)]. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai3mo ago
<@401986039964631060> kapa.ai is still learning and improving, please let us know how it did by reacting below
cryptomax
cryptomax3mo ago
@Normcore Assistant My understanding is that maintainOwnershipWhileSleeping also is not designed ot be changed during runtime correct?
kapa.ai
kapa.ai3mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- Yes, you're correct. The maintainOwnershipWhileSleeping property is not designed to be changed dynamically during runtime. It is typically set in the Unity editor before the game starts. This property determines whether the RealtimeTransform should maintain ownership when the attached Rigidbody goes to sleep. If set to true, the RealtimeTransform will continue to be owned by the local client when the attached Rigidbody goes to sleep, preventing other clients from taking over the simulation for this object. However, it's important to note that changing this property during runtime won't have any effect on the current state of the Rigidbody. If the Rigidbody is already asleep, changing this property won't wake it up or change its ownership. For more information, you can refer to the RealtimeTransform documentation (https://normcore.io/documentation/realtime/realtimetransform#extra-notes). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai3mo ago
<@401986039964631060> kapa.ai is still learning and improving, please let us know how it did by reacting below
Towellie
Towellie3mo ago
Hey @cryptomax did this Solve your issue?
liamc
liamc3mo ago
I think the bot is wrong for the second question and didn't really answer the first question. If you look at RealtimeTransformModel, maintainOwnershipWhileSleeping is synced as part of the PhysicsState bitmask. RealtimeTransform's maintainOwnershipWhileSleeping property just encapsulates a local bool, it doesn't update the model. But, if the realtime transform has a rigidbody it will use the RealtimeTransformRigidbody strategy, which does sync update the maintain ownership property for local and remote users. The owner of the RT will update the model's maintainOwnership property in OnLocalModelWillWrite, and everyone else will read the model's changes in OnRemoteModelDidRead. So it can be changed at runtime, but only by the owner. As for the first question, preventOwnershipTakeover is a flag in the lifetimeFlagsProperty inside the MetaModel. It's a reliable property, so it can by synced at runtime. I don't see any reason why this wouldn't support dynamically being changed at runtime either.
maxweisel
maxweisel3mo ago
fwiw RealtimeTransform will only ever take over unowned transforms you don’t need to use the prevent takeover flags to stop it if you want something to stay owned by own client forever mark the RealtimeView as owned by that client. That will block ownership transfer of child components
liamc
liamc3mo ago
I think ive used the preventOwnershipTakeover flag to indicate to other players that they shouldn't request ownership also. Instead of a player grabbing a prevent takeover object and the server rejecting the ownership request, you just don't allow the player to interact with it if the flag is set and its remotely owned