[SOLVED] Exception when removing a rigidbody component from an entity

Hello,

Game is stuck with this error.

As you can see in image those warning comes often but sometimes those warning comes with this error. I am posting warning and error.

Warning:

playcanvas-stable.dbg.js:42900 removeComponent: Entity doesn't have rigidbody component
Entity.removeComponent	@	playcanvas-stable.dbg.js:42900
GamePlayManager.repairExistingPlayer	@	gamePlayManagerScrip…ce-a5c4e109449b:560
GamePlayManager.startNextRound	@	gamePlayManagerScrip…ce-a5c4e109449b:317
GamePlayManager.update	@	gamePlayManagerScrip…ce-a5c4e109449b:180
_scriptMethod	@	playcanvas-stable.dbg.js:30884
_onUpdate	@	playcanvas-stable.dbg.js:30920
_callComponentMethod	@	playcanvas-stable.dbg.js:31335
_onUpdate	@	playcanvas-stable.dbg.js:31344
_helper	@	playcanvas-stable.dbg.js:26916
update	@	playcanvas-stable.dbg.js:26924
update	@	playcanvas-stable.dbg.js:26337
(anonymous)	@	playcanvas-stable.dbg.js:26712
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698

Error :

Uncaught TypeError: Cannot read property 'body' of null
    at RigidBodyComponent._updateDynamic (playcanvas-stable.dbg.js:33252)
    at RigidBodyComponentSystem.onUpdate (playcanvas-stable.dbg.js:33802)
    at Function._helper (playcanvas-stable.dbg.js:26916)
    at Function.update (playcanvas-stable.dbg.js:26924)
    at Application.update (playcanvas-stable.dbg.js:26337)
    at playcanvas-stable.dbg.js:26712
_updateDynamic @ playcanvas-stable.dbg.js:33252
onUpdate @ playcanvas-stable.dbg.js:33802
_helper @ playcanvas-stable.dbg.js:26916
update @ playcanvas-stable.dbg.js:26924
update @ playcanvas-stable.dbg.js:26337
(anonymous) @ playcanvas-stable.dbg.js:26712
requestAnimationFrame (async)
(anonymous) @ playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)
(anonymous) @ playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)
(anonymous) @ playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)
(anonymous) @ playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)
(anonymous) @ playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)
(anonymous) @ playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)
(anonymous) @ playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)
(anonymous) @ playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)
(anonymous) @ playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)
(anonymous) @ playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)
(anonymous) @ playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)
(anonymous) @ playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)
(anonymous) @ playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)
(anonymous) @ playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)
(anonymous) @ playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)
(anonymous) @ playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)
(anonymous) @ playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)
(anonymous) @ playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)
(anonymous) @ playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)
(anonymous) @ playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)
(anonymous) @ playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)
(anonymous) @ playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)
(anonymous) @ playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)
(anonymous) @ playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)
(anonymous) @ playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)
(anonymous) @ playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)
(anonymous) @ playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)
(anonymous) @ playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)
(anonymous) @ playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)
(anonymous) @ playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)
(anonymous) @ playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)
(anonymous) @ playcanvas-stable.dbg.js:26698

I am not able to understand why this is happening?

Hi @Ketan_ATA,

This is an internal error of the physics engine (Ammo.js), not easy to debug without some context or a build to test with.

Are you manually removing/destroying any rigid bodies or collision components in your code?

1 Like

Yes.

As i come to know this happens sometimes during headshot only…

EnemyThrowArcherStickController.prototype.onDeathFallSamePlaceAnimClipStart = function () {
    try
    {
        
        // to show player falling effect
        var topPartEntity = this.entity.findByName('top');
        var middlePartEntity = this.entity.findByName('middle');
        var bottomPartEntity = this.entity.findByName('bottom');

        this.entity.findByName('headPlayerSprite').enabled = true;
        this.entity.findByName('legsPlayerSprite').enabled = false;
        this.torsoThrowAnimationEntity.enabled = false;

        this.player_dead_sameplaceEntity.enabled = true;
        this.player_dead_sameplaceEntity.sprite.speed = 2.5;


        this.upperBodyEntity.setLocalEulerAngles(0,0,-90);
        this.rotPointerInnerEntity.setLocalEulerAngles(0,0,0);
        topPartEntity.setLocalEulerAngles(0,0,0);

        var spearModel = this.entity.script.enemyStatus.spearWhichGaveHeadshot;

        spearModel.reparent(topPartEntity);    // attach spear to the head
        spearModel.setLocalPosition(0, 0, 0);
        spearModel.setLocalEulerAngles(0, 0, 0);

  
        setTimeout(function(){

            topPartEntity.addComponent("rigidbody");
            topPartEntity.rigidbody.type = pc.BODYTYPE_DYNAMIC;
            // topPartEntity.rigidbody.linearVelocity = velocityOfSpear;
            // topPartEntity.rigidbody.mass = 1;
            topPartEntity.rigidbody.applyForce(topPartEntity.up.scale(100));

        }.bind(this),10);

        
        middlePartEntity.tween(middlePartEntity.getLocalEulerAngles()).rotate(new pc.Vec3(0, 0, -5), 0.7, pc.SineOut).delay(0).start();
        middlePartEntity.tween(middlePartEntity.getLocalPosition()).to(new pc.Vec3(0.7, -0.3, 0), 0.7, pc.SineOut).delay(0).start();

        bottomPartEntity.tween(bottomPartEntity.getLocalEulerAngles()).rotate(new pc.Vec3(0, 0, 88), 0.7, pc.SineOut).delay(0).start();
        bottomPartEntity.tween(bottomPartEntity.getLocalPosition()).to(new pc.Vec3(0.3, -0.7, 0), 0.7, pc.SineOut).delay(0).start();
        // bottomPartEntity.tween(bottomPartEntity.getLocalPosition()).to(new pc.Vec3(0.3, -0.7, 0), 0.7, pc.SineOut).delay(0).on('complete', this.removeEnemy.bind(this)).start();


        setTimeout(function(){
            this.removeEnemy();
        }.bind(this),1000);


        // drop off shield and spear
        this.entity.findByTag('helmet')[0].enabled = false;     // hide helmet
        this.entity.findByTag('shield')[0].addComponent("rigidbody");
        this.entity.findByTag('shield')[0].rigidbody.type = pc.BODYTYPE_DYNAMIC;

        this.throwableWeaponEntity.enabled = false;

    }
    catch(ee)
    {
        console.warn(ee);
    }
};

But i did not get any warning through this… :thinking:
Can u see any thing suspicious?

There’s a bug in the engine when calling pc.Entity#removeComponent for a pc.RigidBodyComponent. Can you log it here please?

1 Like

@will
I posted it here… i am not sure that post is enough or not… :thinking:
You can take a look here… https://github.com/playcanvas/engine/issues/2144

=====================================
@will @Leonidas

Sorry to ask but i am in a trouble here as well…
How long will it take to fix and live those changes in Playcanvas?

Fixed by this PR:

I will probably deploy 1.28.3 later today.

4 Likes

@will
Thanks for update. This update fixed that error.

Just for your information, i can still see some warning like…

Warning 1:

addComponent: Entity already has rigidbody component
Entity.addComponent	@	playcanvas-stable.dbg.js:42893
EnemyThrowSpearStickmanController.onDeathFallAnimClipStart	@	enemyThrowSpearStick…ce-a5c4e109449b:424
EnemyThrowSpearStickmanController.update	@	enemyThrowSpearStick…ce-a5c4e109449b:130
_scriptMethod	@	playcanvas-stable.dbg.js:30884
_onUpdate	@	playcanvas-stable.dbg.js:30920
_callComponentMethod	@	playcanvas-stable.dbg.js:31335
_onUpdate	@	playcanvas-stable.dbg.js:31344
_helper	@	playcanvas-stable.dbg.js:26916
update	@	playcanvas-stable.dbg.js:26924
update	@	playcanvas-stable.dbg.js:26337
(anonymous)	@	playcanvas-stable.dbg.js:26712
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698

Warning 2:

removeComponent: Entity doesn't have rigidbody component
Entity.removeComponent	@	playcanvas-stable.dbg.js:42905
GamePlayManager.repairExistingPlayer	@	gamePlayManagerScrip…ce-a5c4e109449b:560
GamePlayManager.startNextRound	@	gamePlayManagerScrip…ce-a5c4e109449b:317
GamePlayManager.update	@	gamePlayManagerScrip…ce-a5c4e109449b:180
_scriptMethod	@	playcanvas-stable.dbg.js:30884
_onUpdate	@	playcanvas-stable.dbg.js:30920
_callComponentMethod	@	playcanvas-stable.dbg.js:31335
_onUpdate	@	playcanvas-stable.dbg.js:31344
_helper	@	playcanvas-stable.dbg.js:26916
update	@	playcanvas-stable.dbg.js:26924
update	@	playcanvas-stable.dbg.js:26337
(anonymous)	@	playcanvas-stable.dbg.js:26712
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698
requestAnimationFrame (async)		
(anonymous)	@	playcanvas-stable.dbg.js:26698

I am not worried about this warning at all, because the main error issue is fixed.
Anyway thanks again for support and help. :slightly_smiling_face: :+1:t2:

Well, those warnings seem legitimate. They’re telling you you’re trying to add a ‘rigidbody’ component to an entity that already has one. And trying to remove one from an entity that doesn’t have one.

2 Likes