Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Timetravelociraptor · Aug 26, 2017 at 12:52 PM · rigidbodyrigidbody2dsetactiveresetrigidbody.velocity

Why does Rigidbody.OnDisable() reset the velocity?

If you call gameObject.SetActive(false) on an object with a Rigidbody2D, and later SetActive(true), the object will lose its velocity and angular velocity. This consistently happens to me when there's a frame delay between deactivating and re-activating the object (won't work if you immediately call SetActive(true) afterward).

note that changing rigidbody.simulated to false and then true will NOT reset the velocity.

I suspect that this also happens with regular Rigidbody but I only tested this with 2D physics.

This is frustrating, unexpected, unintuitive behavior. Why doesn't it just freeze the velocities until it is reactivated?

Can I find a workaround that does not require me to cache the velocities with a new component (or in a big table somewhere)?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by TheSOULDev · Aug 26, 2017 at 04:03 PM

Frustrating maybe for you, but certainly not unexpected or unintuitive. Think of how much of a bother object pooling would be if you'd have to keep track of physics attributes. If the velocity is not removed, how would Unity keep the object from moving? Or, if it kept moving and OnEnable set it to the original location, how would unity know what location it is without back tracking and recording additional values? The things you want are completely unnecessary, unintuitive and unoptimized.

Setting an object inactive means treating it as non-existent. If it's non-existent, it doesn't travel, and if it's not travelling, it has no velocity.

Meanwhile you, as a programmer, can alter this behaviour. Having rigidbodies tax the game unnecessarily for people who don't need this kind of behaviour would be blasphemous.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bunny83 · Aug 26, 2017 at 04:16 PM 0
Share

Right, active physics objects (aka Rigidbodies) have a representation inside the physics system. When you deactivate an object it's no longer being part of the physics system. At the next physics update (FixedUpdate) the system will detect that the object is deactivated and will remove it from the system. The same happens with colliders.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

90 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Rigidbody.velocity Not working on parent rigidbody with four child rigidbodies attached to it 1 Answer

Kinematic rigidbody movement. 2 Answers

How to lerp a car while it's moving forward at a constant velocity 0 Answers

Rigidbody2D adding force vs modifying velocity for character jump 1 Answer

Add force once when object is created 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges