#Unity flat out ignores request to change useGravity and isKinematic of a rigidbody

1 messages · Page 1 of 1 (latest)

magic crater
#

cs Rigidbody rb1 = grabbedObject.GetComponent<Rigidbody>(); grabbedData.isWelded = true; grabbedData.disableCollisions = true; Debug.Log("about to change grav state"); rb1.useGravity = false; rb1.isKinematic = true; Debug.Log("changed grav state"); EditorGUIUtility.PingObject(rb1.gameObject); EditorApplication.isPaused = true; rb1.constraints = RigidbodyConstraints.FreezeAll;

Both log statements run and it pings the expected object then pauses the game. I click the object and observe the rigidbody and it has not changed either expected value. I have no joints or animators that so much as touch anything related to this object and it has no parent at the time of changing.

sand pollen
magic crater
sand pollen
magic crater
austere minnow
#

Yea pausing meerly means at the end of this frame it will pause and wait
async code keeps goin

magic crater
sand pollen
#

the solution is finding what the problem is

austere minnow
#

test with a compleatly new rigidbody, does it happen there?

magic crater
sand pollen
#

bit of a roundabout debugging method though, but sure

magic crater
magic crater
#

that's important idk how I forgot that

#

that's why I was thinking it wasn't being driven by a script

#

hm ok @sand pollen @austere minnow it did change it after I ran it at the end of the frame

sand pollen
magic crater
magic crater
#

it's as if some code was setting it right after my code was setting it like some sort of race condition

#

at the very least it works now

#

still wanna find the issue

sand pollen
#

I will say this:
⁨```cs
if (isRight) {

}
else if (isLeft) {

}```⁩ thing is a bit of a code smell

#

If there are only two possibilities you should just have one variable for it

#

⁨```cs
if (isRight) {

}
else { // we assume it's left if it's not right
}```⁩

magic crater
#

yeah yeah yeah I was just throwing it together to make it work

sand pollen
#

if you have both of those variables it's possible for both of them to be true or both false which is 😵‍💫

#

but there are several places in this code where you're setting these properties

magic crater
#

the other two don't run until after the issue or aren't triggered at this point

#

and they haven't run yet at all

sand pollen
#

you do have a bunch of logs here

#

without seeing what's printing in the console it's hard to say

magic crater
#

and the debug log at the start of the pull away method never runs

#

the last logs to run besides the ones around the property change that is the issue are the logs at the start of weld

sand pollen
#

Ok, well... I'm not sure then. I'll leave you to debug it, gotta stop procrastinating on my own project now

magic crater
magic crater
#

I think I figured it out

#

My code works so that you can grab objects, move them, then weld them to other objects

#

So while grabbing something you press the weld button, it welds and forces you to release that object

#

it wasn't forcing you to release it fully properly

#

and when you let go of the grip button to stop grabbing after welding it would renable the just disabled physics

#

just have to add some weld checks into the grab release section and modify it a bit so it doesn't re-enable physics after being welded and releases properly

#

this might also fix another issue with the script I had during vr testing which would be amazing

sand pollen