Open kschoos opened 8 years ago
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.
When an entity is created and added to the system,
PhysicsBodyComponent.body
will not be instantiated. It only gets instantiated after a null check inPhysicsSystem::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()
fromComponentFactory::createPhysicsComponents()
. At that point we have all the information we need to build the physicsbody if I am not mistaken.SpineComponentFactory::createComponents(...)
andCompositeComponentFactory::createComponents(...)
both callpractically creating the same object twice. In case we call
PhysicsBodyLoader::createBody()
fromComponentFactory::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 ?