Remove a body in PhysicsServer

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Macryc

Hi. The PhysicsServer class allows me to create rigid bodies and applying force to them etc. without creating nodes.

Question is: How do I remove/delete a body I created via PhysicsServer.create_body?? There is no PhysicsServer.remove_body(). You can only remove shapes. I am using this for projectiles. A minute into the game, with hundreds or thousands of bodies having been created in this way the engine starts choking. I want to be able to remove a body after, say, It has flown an x distance away from its spawn position. How do I ‘free’ a physicsserver body??

:bust_in_silhouette: Reply From: Gluon

You need queue_free()

so the code would be something like

get_node("your_rigid_body").queue_free()

It’s not a rigid body. It’s not even a node. It’s a RID. queue_free doesn’t work with RIDs in physics servers.

Macryc | 2021-11-27 16:51

:bust_in_silhouette: Reply From: timothybrentwood

Use PhysicsServer.free_rid()

https://docs.godotengine.org/en/stable/classes/class_physicsserver.html#class-physicsserver-method-free-rid