This project has moved and is read-only. For the latest updates, please go here.

Re-Using Joints and Body Bugs Please Help

Topics: Developer Forum, User Forum
Oct 5, 2011 at 5:38 PM

Hi I was wondering is it ok to change bodies on a joint without creating a whole new one.  I am getting some weird behavior.  I will load the level of the game I am making, then once I reload the level the joints wont stick together anymore sometimes.  When I reload the level I sent all the object back to their pools and disable any joints or bodies that are in that object.  Then once I reload the level and connect the joints back up to a new body the joint just does not work and anything connected to it will just drop.  I can see in the debug view that the joint is still connected.  What is going on here.  Is there something I can do to prevent this and has this issue came up before?

Also there is a problem with the bodies I am using.  My player rig works just fine.  But there seem to be a problem with my items.  I pin them to the players hand when they are using them and pin them to the players belt when not.  I set it up properly and assign the oncollision event.  It seems sometimes after reloading a level or going the next level somehow messes with the body.  Sometimes when I load a level the items on the belt will fight to get off the player and spin the player out of control.  It will also create a error when i drop an item and it hits the bottom of the level where it is turned off.  Once that happens I get an error in the contact class that the fixture is null.  Is there some sort of order I need to implement bodies or reuse them that I am not aware of?

And there is one more problem.  I was just stress testing a level to see how many items I could put up before things go slow.  I noticed something weird when I did.  I would load the first level with about 40 items or so.  It would be running quite slow at first and I noticed in the debug info that there were about 6000 contacts.  Then I would reload the level and then it would run smooth as could be and the contacts would go down to 600.  Do you have any clue what might be happening?  Thanks

Oct 7, 2011 at 12:49 AM


Oct 7, 2011 at 10:53 AM

I think you should remove the joints from the world -with World.RemoveJoint(jointToRemove)- then you should disable the bodies if needed. Later when you want to reuse a joint, just reassign the bodies (remember to modify the anchors too, as they are local for the attached bodies) and add them again to the world with World.AddJoint(jointToAdd).