Currently at work so I don’t have any code to post at the moment but wanted to go ahead and get the concept of my issue out here.
My BulletAppState contains everything from my Level1 AbstractAppState, which is a bunch of Geometries with RigidBodyControls. All of the geometries are added to a single spatial then attached to the rootNode all at once.
I tried using this spatial in the physics removeAll and also tried looping through all of the children of the spatial on using remove to remove level1 physics from the BulletAppState but neither of these methods worked for me.
To make each geometry for the level, I do the following:
- Create geometry
- Add new RigidBodyControl
- Attach geometry to parent spatial
- Attach geometry to BulletAppState
If I place a breakpoint after the attach to BulletAppState and look at the geometry I noticed that the control list is now empty where before it contains 1, which was the RigidBodyControl. I know understand that is why I could not remove the control from the BulletAppState on cleanup using the geometry list.
So considering the only other physics control in the BulletAppState is the one for my character I decided to just destroy the BulletAppState and recreate it on each level load. Once the level is loaded I will add the existing character to this new BulletAppState. This works great on the desktop version but when I test this on Android the adding of the existing character’s CharacterControl causes my app to crash with “Unfortunately the game has stopped working” or something along those lines. I have the log output set to ALL and do not see an error at the time this crash occurs. If I detach the character AbstractAppState and recreate it after loading the second level it works fine on Android.
That being said the issue seems to be directly related to adding the existing CharacterControl to the new BulletAppState, but as to why this error is occurring on Android I’m in the dark.
As I’m still new to jmonkey I figured I would post this in hopes of someone being able to give me some ideas to try out by the time I make it home.