I am currently working on making a physics demo in GDExtension and am creating a class which (with any luck) will handle its own collision resolution. However for this question, that is neither here nor there.
I have run into a little bit of a speed-bump. I am trying to add a body to the PhysicsServer3D (using body_create()), and want it to be in the same space as a RigidBody3D would be added to automatically. It doesn’t add the body to any space by default (the space RID for the new body is 0 and the space RID for a regular RigidBody3D is a very large number).
The only way I have thought of is to look up a RigidBody3D node in the tree by name, and then using get_rid and PhysicsServer3D::body_get_space(). This doesn’t seem like a great idea, since I would ideally like this to be robust to changes in the scene tree.
TLDR; How would you go about finding the RID of the “default” space in PhysicsServer3D?
PS. I am not sure if there is a constant value for the default space. Between runs, I have gotten RID(4471060955136) consistently, but I need this demo to be able to run on other systems – not just mine.
Let me know if you have the same RID value for the default space on your system, if you are reading this and want to help!
I will send another reply here if I encounter any breakthroughs in the meantime!
There is no default space in the SceneTree, there is a space per World2D/World3D of a Viewport.
If a Viewport does not use a unique world it uses the world of its parent Viewport. The SceneTree never has anything to do with any of those “world rids”. E.g. visual rendering scenario, physics space, navigation map, …
Theoretically you can get the SceneTree and Viewport for the main RIDs but as soon as a user project uses mutliple Viewports and Worlds that no longer will work. That is why each node type gets the current RID from its viewport world and those RIDs can be always different id numbers.