Closed jordo closed 3 years ago
This seems to be the primary folly of using a node to represent the physics space. Godot doesn't have this issue because it uses a physics server singleton.
Having the world as a singleton may be the only way to resolve this. We can keep Box2DWorld as a node to create spaces other than the singleton.
I believe the code to look at is https://github.com/briansemrau/godot_box2d/blob/4.0/scene/2d/box2d_physics_body.cpp#L147 (as well as in Fixture and Joint)
My initial guess at a solution would be to make a modification to look for the singleton world in case one is not found in the scene tree.
I dunno, i'm not 100% sure about it. I'm not a huge fan of singletons, and think there's a chance we don't need the world to do body and fixture setup.
We could also default to having at least a global world available at the root, if you never add another one. Going to investigate further, but you could be right.
IIRC The 'real root' in godot, is kinda above what you see above the scene tree (there's kinda one global root that loads scenes underneath it). I think that's the case. If that is the case, we can keep the 'World' lookup code the same (traverse up the tree until you find a world)
Alright, this should be working with https://github.com/briansemrau/godot_box2d/pull/31
Does this issue include the scope of running sub-scenes, even if just for testing? The current PR seems to make things better in the editor, but is limited to that.
sub-scenes should work, at least they do in my test project. I've got the body nodes in subscenes below my world
GameData looks like this:
I still like the warnings, cause it still give the user a warning that they need to know what they are doing for this to work
If you run this sub-scene, however, it won't work, right? Because there is no b2world
ya, that's correct. OK, i see what you are saying now.
So hmm, i feel like that is OK. If users set things up like this they should know what they are doing.
At least the warnings make it very clear. It's possible this will come up as an issue in the future, but it'll likely be handled when all the b2 stuff is put into a server. Topic for the future.
closing with #32 as followup to the discussion had
during porting of my project, I discovered that obviously physics bodies and fixtures need to be supported in sub-scenes. i.e, the scene doesn't hold a world node, but is attached to another node which contains the world. In the screenshot below GameData scene is included in another scene (which contains the box2d world).
Going to investigate how to support this.