Ensuring Rigidbodys are asleep when not needed

I have a game with 500-1000 Rigidbodys but only a small proportion of those rigidbodys are used. Client 1 starts the game and all rigidbodys with RealtimeViews and RealtimeTransfoms are sleeping. All rigidbodies have a simple rigidbody.Sleep() method in the start event function. Client 2 starts the game but for some reason that I do not understand, subsequent clients start with all rigidbodys being awake. Having checked in the inspector as client 2, I can see that the current owner of these awake rigidbodys is None. How do I ensure if a rigidbody is not being interacted with, it is asleep for all clients?
4 Replies
kapa.ai
kapa.ai2w ago
Hi @JimJamesJimJim. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- To address your question about ensuring Rigidbodies are asleep when not needed in a NormalVR multiplayer context, let's look at how RealtimeTransform works with Rigidbodies and ownership. RealtimeTransform behaves differently when a Rigidbody is present. According to the RealtimeTransform documentation: 1. RealtimeTransform will automatically clear ownership when the Rigidbody goes to sleep. 2. When a Rigidbody RealtimeTransform collides with another Rigidbody RealtimeTransform, it will attempt to request ownership of the second object if it has no owner. The behavior you're experiencing, where Client 2 starts with all Rigidbodies awake, might be related to how ownership and sleep states are synchronized across clients. To ensure Rigidbodies are asleep for all clients when not being interacted with, consider the following approaches: 1. Use the "Maintain Ownership While Sleeping" option: If you want to prevent RealtimeTransform from automatically clearing ownership when the Rigidbody goes to sleep, you can enable this option in the inspector. This might help maintain the sleep state across clients. As mentioned in the RealtimeTransform documentation: "If you would like to avoid this behavior, use the inspector to switch the sleep option to 'Maintain Ownership While Sleeping.'" 2. Implement custom logic to manage sleep states: You might need to implement custom logic to ensure Rigidbodies are put to sleep when they're not being interacted with. This could involve: - Periodically checking for inactive Rigidbodies and putting them to sleep. - Using RealtimeTransform's ownership methods to manage which client is responsible for each Rigidbody. 3. Consider using kinematic Rigidbodies: For objects that don't need constant physics simulation, you might want to make them kinematic when not in use. As noted in the documentation: "When implementing logic like picking up an object, we recommend marking the rigidbody kinematic. While a rigidbody is kinematic, ownership will not be cleared automatically, and the default sleep settings can be used." 4. Ensure proper ownership management: Make sure you're not inadvertently requesting ownership of all Rigidbodies when a new client joins. Review your initialization code to ensure you're only requesting ownership when necessary. It's important to note that Unity's physics engine (PhysX) is not deterministic, which can lead to differences in physics states across clients. Normcore implements custom prediction and smoothing techniques to handle this, as mentioned in the Networked Physics documentation. If these approaches don't solve your issue, you might need to implement a more custom solution or reach out to the NormalVR support team for further assistance, as the provided knowledge sources don't contain enough information to fully diagnose and solve this specific scenario. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai2w ago
<@351655082145611778> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
Mechabit
Mechabit2w ago
you can just use the Sleep() command on all unowned rigidbodies locally on client 2
cryptomax
cryptomax2w ago
you can also set them to kinematic to be rock sure they aren't in the physics sim. Max said that kinematic setting is synced between clients by realtimetransform i've certainly had trouble getting RB's to stay asleep

Did you find this page helpful?