Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PhysicsBodyComponent.body is null #83

Open
kschoos opened this issue Feb 1, 2016 · 1 comment
Open

PhysicsBodyComponent.body is null #83

kschoos opened this issue Feb 1, 2016 · 1 comment

Comments

@kschoos
Copy link

kschoos commented Feb 1, 2016

When an entity is created and added to the system, PhysicsBodyComponent.body will not be instantiated.
It only gets instantiated after a null check in PhysicsSystem::processBody(). This means that we would have to wait for 1 engine tick in order to be sure all physics objects are properly instantiated.

A fix would be to call PhysicsBodyLoader::createBody() from ComponentFactory::createPhysicsComponents(). At that point we have all the information we need to build the physicsbody if I am not mistaken.


SpineComponentFactory::createComponents(...)and CompositeComponentFactory::createComponents(...)both call

ComponentFactory::createCommonComponents(entity, vo, ...);
ComponentFactory::createPhysicsComponents(entity, vo)

practically creating the same object twice. In case we call PhysicsBodyLoader::createBody() from ComponentFactory::createPhysicsComponents() it even creates two bodies at the same spot.


Maybe also implementing float PhysicsBodyComponent.initialAngle and Vector2 PhysicsBodyComponent.initialPosition could make it easier to instantiate an object at the right position and rotation ?

@kschoos kschoos changed the title physicsBodyComponent.body is null 🐛 physicsBodyComponent.body is null Feb 1, 2016
@kschoos kschoos changed the title physicsBodyComponent.body is null PhysicsBodyComponent.body is null Feb 1, 2016
@BionicFelps
Copy link
Contributor

Probably related, I'm attempting to add physics bodies at runtime, which I think would be fairly common for making bullets, etc. But in this case I'm making a more complex physics object with a circle and a box to represent bipedal enemies, they'll turn their circle to go left or right, I've tried initiating this in Create() as well as in the second run of processEntity in my custom system, in all of my code the physics body exists, even after the functions leave scope, but at some point Overlap sets the physics body to null, and then later tries to use it, causing a catastrophic crash.

I've also tried doing this on the five thousandth iteration just to be sure any and all setup should be done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants