physics.addBody cannot be called when the world is locked and in the middle of number crunching such as during a collision event

function scene:create( event ) local sceneGroup = self.view physics.start() ---------------------------- local BackGround = display.newImageRect("BackGround.png", 1080, 1920) local floor = display.newImageRect("floor.png", 351, 32 ) floor.x = display.contentWidth \* 0.5 floor.y = 520 physics.addBody(floor, "dynamic") return true end

thats the code that makes the image pop up… says that error on line 32 which is “physics.addBody(floor, “dynamic”)”

ive tried static and other things . physics is on… maybe is something with the collision that i want happen… but when i remove all the collision functions and locals it still gives the error… i tried making a timer didnt seem to work maybe i did it wrong idk thanks for any help

@roaminggamer

Can you please paste in the error message you are seeing? 

That is exactly the error code I’m.seeing… In the title

Hi @SonicX278,

Several physics functions/APIs cannot be called during a collision event, just as the warning message says. You need to perform these type of operations after a very short timer (10-50 milliseconds) so that the actual operation occurs in the next frame step of the runtime, after the physics engine has done its calculations for the collision and so forth.

This guide indicates all of the physics APIs which pertain to this rule:

https://docs.coronalabs.com/guide/physics/collisionDetection/index.html#collision-handling

Take care,

Brent

so do i add a timer delay to the image? because i tried and i couldnt seem to get it working…

@Brent Sorrentino

thanks

ohh i figured it out :slight_smile: i need to put the physics object into my scene show scene … thanks for the tips tho they will help me in the future :slight_smile:

Can you please paste in the error message you are seeing? 

That is exactly the error code I’m.seeing… In the title

Hi @SonicX278,

Several physics functions/APIs cannot be called during a collision event, just as the warning message says. You need to perform these type of operations after a very short timer (10-50 milliseconds) so that the actual operation occurs in the next frame step of the runtime, after the physics engine has done its calculations for the collision and so forth.

This guide indicates all of the physics APIs which pertain to this rule:

https://docs.coronalabs.com/guide/physics/collisionDetection/index.html#collision-handling

Take care,

Brent

so do i add a timer delay to the image? because i tried and i couldnt seem to get it working…

@Brent Sorrentino

thanks

ohh i figured it out :slight_smile: i need to put the physics object into my scene show scene … thanks for the tips tho they will help me in the future :slight_smile: