In this page: Struct PhysicsVelocity | Unity Physics | 0.51.1-preview.21
It says: “The velocity of a rigid body. If absent, the rigid body is static.” But how?
So, who can tell me, how to absent “PhysicsVelocity”? Thanks!
In this page: Struct PhysicsVelocity | Unity Physics | 0.51.1-preview.21
It says: “The velocity of a rigid body. If absent, the rigid body is static.” But how?
So, who can tell me, how to absent “PhysicsVelocity”? Thanks!
EntityManager.RemoveComponent<PhysicsVelocity>(entity);
or if using EntityCommandBuffer:
commandBuffer.RemoveComponent<PhysicsVelocity>(entity);
if you mean in terms of Authoring then don’t add a PhysicsBody component on GameObject just use a PhysicsShape component and the authored entity will be static.
Thank you for your reply!
Actually I need the traditional Rigidbody sleep effect: Rigidbody.Sleep(). When the character leaves an area, those entities no longer need to do physical calculations, thereby freeing up CPU computing resources. Reactivate the rigid body when needed, just like Rigidbody.Weakup().
If I remove in DOTS, and when I need it then add it, just like you wrote : EntityManager.AddComponent(entity).
But I remember that this kind of operation of add/remove components belongs to “structural change”. It seems that it can only be performed in the mainthread, right? It seems that it cannot be executed in the general SystemBase:OnUpdate(). I will try more, such as ForEach(), IJobxxx, ECB, etc.
You can use an EntityCommandBuffer to Add/Remove in a job which is not on the main thread, but yeah eventually it will be called at a sync point on the main thread. I don’t think Unity.Physics has a sleep method in place.
Yeah, with the deepening of use, more and more found the imperfection of DOTS.