Andrei Vaduva
Andrei Vaduva2mo ago

RequestOwnership not working

I'm having an issue with request ownership. I have a single RealtimeView and a single RealtimeModel on an object, both of them have ownership none and i can't RequestOwnershipOfSelfAndChildren(). Should i see some errors? it's a rigidbody with maintain ownership while sleeping
13 Replies
kapa.ai
kapa.ai2mo ago
Hi @Andrei Vaduva. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Based on the information provided, there could be a few reasons why RequestOwnershipOfSelfAndChildren() is not working as expected. 1. Connection to the room: The RequestOwnership() method will throw an exception if the model is not part of a connected room, as it requires the local clientID. Make sure that your object is part of a connected room before trying to request ownership (source (https://normcore.io/documentation/reference/classes/Normal.Realtime.RealtimeModel)). 2. Prevent Ownership Takeover: If the preventOwnershipTakeover flag is set to true on any model, the server will deny any client’s attempt to change the ownership of an object in that model unless it has no owner. Make sure this flag is not set to true (source (https://normcore.io/documentation/room/ownership-and-lifetime-flags#prevent-ownership-takeover-of-a-realtimeview)). 3. Rigidbody Mode: If your object is a Rigidbody, RealtimeTransform works a bit differently. It will automatically clear ownership when the Rigidbody goes to sleep to allow other clients to take it over and simulate it. However, you mentioned that you have set "Maintain Ownership While Sleeping", so this should not be an issue (source (https://normcore.io/documentation/realtime/realtimetransform#rigidbody-mode)). 4. Debugging: If you're trying to debug ownership settings at runtime, the RealtimeView inspector includes Request Ownership and Clear Ownership buttons that function like calling RequestOwnership() or ClearOwnership() in code. You can use these buttons to help debug your issue (source (https://normcore.io/documentation/room/ownership-and-lifetime-flags#at-runtime-with-the-unity-inspector)). If none of these solutions work, it might be helpful to check the Normcore documentation or forums for additional help. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai2mo ago
<@1217086475661738045> kapa.ai is still learning and improving, please let us know how it did by reacting below
Andrei Vaduva
Andrei Vaduva2mo ago
@Normcore Assistant if client 1 has ownership, can client 2 request ownership? I'm trying to pass a ball from one player to another and it should maintain ownership until player 2 grabs the object
kapa.ai
kapa.ai2mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- Yes, client 2 can request ownership of an object even if it is currently owned by client 1. The RequestOwnership() function can be used to request ownership of a RealtimeView or RealtimeTransform component. If client 1 is currently the owner, client 2 can call RequestOwnership() to take over ownership (source (https://normcore.io/documentation/room/ownership-and-lifetime-flags#requestownership--clearownership)). However, there are a few things to keep in mind: 1. Prevent Ownership Takeover: If the preventOwnershipTakeover flag is set to true on the RealtimeView or RealtimeTransform, the server will deny any client’s attempt to change the ownership of an object in that model unless it has no owner. Make sure this flag is not set to true (source (https://normcore.io/documentation/realtime/realtimeview#ownership--lifetime-flags)). 2. Rigidbody Mode: If your object is a Rigidbody, RealtimeTransform will automatically clear ownership when the Rigidbody goes to sleep to allow other clients to take it over and simulate it. However, you can set "Maintain Ownership While Sleeping" to avoid this behavior (source (https://normcore.io/documentation/realtime/realtimetransform#rigidbody-mode)). 3. Ownership Transfer on Collision: If you want to transfer ownership based on physics collisions, you need to ensure that the RealtimeView has no owner. If you request ownership of both the transform and the view, the RealtimeTransform may not properly transfer ownership on collision (source (https://normcore.io/documentation/realtime/common-questions#why-doesnt-my-realtimetransform-properly-transfer-ownership-on-collision)). Here's a simple example of how you can request ownership:
// Get the RealtimeView component
RealtimeView myObjectView = myObject.GetComponent<RealtimeView>();

// Request ownership of the RealtimeView
myObjectView.RequestOwnership();
// Get the RealtimeView component
RealtimeView myObjectView = myObject.GetComponent<RealtimeView>();

// Request ownership of the RealtimeView
myObjectView.RequestOwnership();
Remember, in order to move an object with a RealtimeTransform component, your client needs to be the owner of the RealtimeTransform component (source (https://normcore.io/documentation/realtime/realtimetransform#how-it-works)). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai2mo ago
<@1217086475661738045> kapa.ai is still learning and improving, please let us know how it did by reacting below
Mechabit
Mechabit2mo ago
if the view is owned by player 1 then player 2 will need to request ownership of both the view and the realtime transform. otherwise you can just request ownership of the realtime transform
Andrei Vaduva
Andrei Vaduva2mo ago
@Normcore Assistant i have an OnUngrab -> that sets a rigidbody velocities and i want right after i set the velocities to change the ownership to the other player (it's a 2 player game) so that the physics are simulated by the other side. If i set the velocities and then run SetOwnership(client2) the ball remains stuck in the air. If i set the velocities and on the next frame i run SetOwnership(client2) the ball simulates but the owner quickly changes to Remote Client then back to Local client
kapa.ai
kapa.ai2mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- Based on the information provided, it seems like you're trying to pass ownership of a Rigidbody object from one player to another in a two-player game. When the object is ungrabbed, you want to set the Rigidbody's velocities and then immediately transfer ownership to the other player so that the physics are simulated on their side. However, you're encountering an issue where the ball gets stuck in the air if you set the velocities and then immediately call SetOwnership(client2). If you delay the SetOwnership(client2) call to the next frame, the ball simulates correctly, but the owner quickly changes to the Remote Client and then back to the Local client. This issue might be related to how RealtimeTransform handles ownership and physics simulation. When a Rigidbody object is owned by a client, that client's simulation is considered the source of truth for that object. RealtimeTransform synchronizes the state of the object from the owner to all other clients (source (https://normcore.io/documentation/realtime/networked-physics#ownership--physics)). If you're trying to directly move an object, make sure to mark it kinematic. Doing so lets PhysX know that you're controlling its position and it should not simulate the object directly. It also tells RealtimeTransform that it should not clear ownership when the object goes to sleep (source (https://normcore.io/documentation/realtime/networked-physics#realtimetransform--physics)). However, if you're in a situation where you need to maintain ownership while sleeping, you can always set Maintain Ownership While Sleeping in the Unity editor (source (https://normcore.io/documentation/realtime/networked-physics#realtimetransform--physics)). If none of these solutions work, it might be helpful to check the Normcore documentation or forums for additional help. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai2mo ago
<@1217086475661738045> kapa.ai is still learning and improving, please let us know how it did by reacting below
Andrei Vaduva
Andrei Vaduva2mo ago
well that didn't help 😅 @Normcore Assistant when throwing a rigidbody, while the rigidbody has a velocity, if i change the ownership from client 1 (thrower) to client 2, client 2 will see everything smooth but client 1 will see a stutter, like the ball is going back a bit then continues the simulation.
kapa.ai
kapa.ai2mo ago
Let me check the knowledge base for you. One moment! :books: ---------------------- The issue you're experiencing might be due to how physics and ownership are handled in Unity and Normcore. When you change the ownership of a Rigidbody object while it's in motion, the new owner (client 2 in your case) needs to synchronize the object's state with its own physics simulation. This can cause a brief stutter or lag in the object's movement, especially if there's a significant difference in the physics simulations between the two clients. Here are a few things you can try to mitigate this issue: 1. Interpolation: Make sure you're using interpolation to smooth out the movement of the Rigidbody. This can help reduce the visible impact of the ownership change. Unity's Rigidbody component has an interpolation setting that you can set to Interpolate or Extrapolate. 2. Networked Physics: Normcore's RealtimeTransform component has a Rigidbody mode that's designed to handle networked physics. In Rigidbody mode, RealtimeTransform synchronizes the world position and rotation values in addition to all Rigidbody settings. This is because Unity's physics engine (PhysX) works entirely in world space (source (https://normcore.io/documentation/realtime/realtimetransform#rigidbody-mode)). 3. Ownership Transfer: When a Rigidbody RealtimeTransform collides with a second Rigidbody RealtimeTransform, it will attempt to request ownership of this second object as well, so the same client can simulate both of the objects in the collision. This can help ensure that the physics simulation stays consistent during the ownership transfer (source (https://normcore.io/documentation/realtime/realtimetransform#rigidbody-mode)). 4. Maintain Ownership While Sleeping: If you want to maintain ownership of the Rigidbody while it's sleeping (i.e., not moving), you can set the maintainOwnershipWhileSleeping property to true on the RealtimeTransform component (source (https://normcore.io/documentation/reference/classes/Normal.Realtime.RealtimeTransform)). Remember, networked physics can be complex and challenging to get right, especially in a fast-paced, real-time game. It might take some experimentation and fine-tuning to get the results you want. If you're still having trouble, consider reaching out to the Normcore community or support for more specific advice. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai2mo ago
<@1217086475661738045> kapa.ai is still learning and improving, please let us know how it did by reacting below
Mechabit
Mechabit2mo ago
This is due to the way lag compensation works, you're always a small amount of time behind what the actual simulation is. In my air hockey game I removed all back-time smoothing and increased the send rate which reduces the amount of back sliding when you switch owners but it also makes lag spikes more obvious. A better solution would be to predict where the ball will be on the client or to use deterministic physics without ball ownership.
More Posts
is 2021 version is updated one? which is available on unity asset stoream wokring on a multiplayer project , i justr wanted to know if the plugin on unity store is updatedHandling Ownership Requests that are older than the newest requestsHello! In our multiplayer soccer game, we are facing an issue about ball ownership which causes the Unity Crashing ~10 seconds after loading realtime with a certain name.Hey guys, Having a rather strange issue. Recently all of our developers started reporting crashes aRealtimeAvatarVoice component for Voice chat is goneAccording to documentation, I'vs used RealtimeAvatarVoice component to use Voice chat. But after updWhat is the best way to seamlessly move between two rooms?Is this possible with a single, real-time instance? I'm working in VR and I want to avoid the AvatarMetaAvatar breaks recenteringI have Allow Recenter deactivated (OVRCameraRig) and when i have MetaAvatars disabled, everything wo[TESTING] How to set up Meta Avatars with NormcoreHey, can you walk me through using Meta Avatars with Normcore?How to best synchronize a byte array?I have a texture2D and I want to be in sync with everyone in the room so I converted the data into aIs it better to have more variables per RealtimeComponent?Say that I have 5 variables that I want to sync using a RealtimeComponent. Is it better to use 1 ReaDoes consolidating RealtimeComponents to have only one RealtimeView reduce bandwidth?For example, if I have a prefab with a root game object and a child game object. For some reason, as