BEPU Physics objects dissapearing on scene change.

rated by 0 users
This post has 13 Replies | 3 Followers

Top 150 Contributor
Posts 16
SunBurn_Community_Licensee
n0rtygames Posted: 02-04-2012 10:40 AM

Hi all,

I'll try and keep this post as brief and to the point as possible. In my project I have a couple of scenes - with the intention of getting functionality in to load different levels at run time and allow editting within the games editor.

This part is successful as follows:

if (keystate.IsKeyDown(Keys.X))

            {

                sceneInterface.Clear();

                sceneInterface.ObjectManager.Clear();

                sceneInterface.LightManager.Clear();

            }

 

            if (keystate.IsKeyDown(Keys.Z) && !lastKey.IsKeyDown(Keys.Z))

            {

 

                sceneInterface.Submit(scene);

 

            }

            if (keystate.IsKeyDown(Keys.C) && !lastKey.IsKeyDown(Keys.C))

            {

                sceneInterface.Submit(secondScene);

            }

 

However the problem I'm having is that any BEPU physics objects I've added to my scene basically seem to stop functioning. Debug wireframes for them stop rendering, no physics occur at all. The scene objects are still there, I can see the models in their correct places - but none of the attached physics components (added via the editor) seem to be retained.

I'm assuming that this will all be discovered once I learn about physics component integration in to my project - though a gentle nudge in the right direction to get me thinking straight would be appreciated! :-)

Cheers,

Steve

Top 10 Contributor
Posts 783
SunBurn_Community_Licensee
SunBurn_Contributor

Hi Steve.

I don't think I'm quite following what you mean.  If you unload one scene then all the scene objects in that scene are unloaded and hence any physics components you have attached will also be unloaded.  If there are physics components attached to scene objects loaded in the 2nd scene then they should be active.  Is that not what's happening?   :(

 

Top 150 Contributor
Posts 16
SunBurn_Community_Licensee

Hiya CJ,

 

That's correct. Basically my physics objects are only active when I first load up my project. Clearing out the scene manager and then submitting a new scene adds all scene objects in and the editor reports that physics components are attached - however I can't see any signs that they're actually there and active in game after this submission takes place.

I then resubmit my scene - all sceneobjects are present. If I turn on debug rendering, I see no evidence of physics objects being present. Ensuring that suspend physics is turned off - I see no activity.

For example, the second scene simply has a floor and a cube about a meter above with a BEPUBox component on it. This doesn't fall to the ground (despite being told to update, being dynamic and being affected by gravity) - which is the behaviour I get on the first run of the game on my other objects.

 

If clear the scene and resubmit scene 1 - the same symptoms are present.

 

Top 10 Contributor
Posts 783
SunBurn_Community_Licensee
SunBurn_Contributor

Hmmm.... strange.  It doesn't appear to be calling the OnAddedToParentObject method on the components when the next scene is loaded.  I have no idea why because it definitely gets called after the first scene has been submitted.

Could it be a SunBurn bug or are we doing something wrong?

 

Top 10 Contributor
Posts 783
SunBurn_Community_Licensee
SunBurn_Contributor

It doesn't seem to call OnInitialize either.

:-(

Top 150 Contributor
Posts 16
SunBurn_Community_Licensee

Something else I'm noticing with the debug renderer turned on is that if I'm loading scene1 - the wireframes for scene2 are present despite that scene not being submitted to the scenemanager yet.

Are there any tests I might be able to do to help resolve what's causing this behaviour? As you might have gathered, physics engines are not my strong point.. yet! :)

Top 10 Contributor
Posts 783
SunBurn_Community_Licensee
SunBurn_Contributor

n0rtygames:
As you might have gathered, physics engines are not my strong point.. yet! :)

Nor are they mine!  LOL.

n0rtygames:
if I'm loading scene1 - the wireframes for scene2 are present despite that scene not being submitted to the scenemanager yet.

That is weird!  I'm seeing the same too.  I'll let you know when I've figured out what's going on.

 

Top 10 Contributor
Posts 783
SunBurn_Community_Licensee
SunBurn_Contributor

I'm getting the feeling this is all to do with my misunderstanding of how OnAddedToParentObject works... or more specifically when it gets called.  It appears to be called for both scenes when they are loaded rather than when they are submitted to the scene interface, which would explain why it isn't being called again when switching scenes.  My bad!

I should probably use OnSubmittedToManager instead.  I'll try it out and let you know.

Top 10 Contributor
Posts 4,854
Employee
SunBurn_Studio_Licensee

Hi guys,

Yes, the OnAddedToParentObject() event is called when the component is added to an object.  This can occur when adding components in code, in the editor, or when the scene is first deserialized (loaded from disk).

The OnSubmittedToManager() / OnRemovedFromManager() events are more relevant as these let you know exactly when the component's parent object is placed in or removed from the scene graph (when it's active in the game).

Let me know if this helps!

Follow me on Twitter – development and personal tweets
Awesome XNA Videos – Lighting, Rendering, and game videos

Top 10 Contributor
Posts 783
SunBurn_Community_Licensee
SunBurn_Contributor

Thanks John.  Much appreciated.

Top 10 Contributor
Posts 783
SunBurn_Community_Licensee
SunBurn_Contributor

Hi Steve.  I think I've managed to fix all our current issues and am about to package up a new release (this time with source code!).

Just to clarify....

Issue with switching scenes is now fixed.

Issue when adding a physics component via code and immediately applying a force is fixed.

 

Is there anything else you've noticed before I upload the new version?  Also, any features you'd like to see implemented?  (I may regret asking that!  LOL!)

Thanks for all your input.

:)

Top 10 Contributor
Posts 783
SunBurn_Community_Licensee
SunBurn_Contributor

New release (v1.0.17) uploaded.

:-)

Top 150 Contributor
Posts 16
SunBurn_Community_Licensee

Hey CJ!

 

CJ Bailey:

Hi Steve.  I think I've managed to fix all our current issues and am about to package up a new release (this time with source code!).

Just to clarify....

Issue with switching scenes is now fixed.

Issue when adding a physics component via code and immediately applying a force is fixed.

Great work! I've just had a chance to confirm that the application of forces works in the way I was using it. Now I can get to work on this player controller...:-)

 

Is there anything else you've noticed before I upload the new version?  Also, any features you'd like to see implemented?  (I may regret asking that!  LOL!)

Thanks for all your input.

:)

Sorry, it looks like I was a bit slow on the forums today. Nothing off the top of my head, so don't worry - you're safe! I wouldn't dare to put out feature requests, so you're safe there too! I will of course add to this thread if anything major jumps out at me.

In all honesty though this plugin has made physics integration quick and painless, you've done a great job. It's pretty intuitive to use once you get your head around the basic implementation.

If it helps at all, I'll turn the rambling on this thread in to some sort of cohesive 'Beginners Documentation' for you as I explore using the plugin, so people can hit the ground running.

 

I'll be trying to get a first person controller system together that collides with and reacts to an environment made from BEPU Physics components - now that you've made these alterations I'm pretty sure this is going to be a trivial exercise!

 

Cheers,

Steve

Top 10 Contributor
Posts 783
SunBurn_Community_Licensee
SunBurn_Contributor

Hi Steve!  Thanks for the great feedback.

n0rtygames:
If it helps at all, I'll turn the rambling on this thread in to some sort of cohesive 'Beginners Documentation' for you as I explore using the plugin, so people can hit the ground running.

That would be awesome!  I'm really struggling for time at the moment (and to be honest not great at writing tutorials and stuff).

Actually, I've got a bit of code that might help with your first person controller (certainly with the terrain following).

2133.SeekComponent.txt

Cheers.

CJ.

 

Page 1 of 1 (14 items) | RSS