Issue with havok

createprimitive(args) {
  const physicsEngine = activeScene.getPhysicsEngine();
  console.log(physicsEngine)
  const object = BABYLON.MeshBuilder[`Create${args.type}`](args.name, {}, activeScene);
  if(args.physicsType === 'static'){
    object.physicsBody = new BABYLON.PhysicsBody(object, BABYLON.PhysicsMotionType.STATIC, activeScene);
  }
  if(args.physicsType === 'dynamic'){
    object.physicsBody = new BABYLON.PhysicsBody(object, BABYLON.PhysicsMotionType.DYNAMIC, activeScene);
  }
  if(args.physicsType === 'kinematic'){
    object.physicsBody = new BABYLON.PhysicsBody(object, BABYLON.PhysicsMotionType.KINEMATIC, activeScene);
  }
  objects.set(args.name, object);
}

I’m getting Promise rejected in compiled script: TypeError: Cannot read properties of undefined (reading 'removeBody')

Could you share a repro in the playground ?

cc @Cedric

Hi @TadKing42 a repro would make our life easier.
It might be a bad init. Did you check this doc page about Havok initialization? Babylon.js docs

createprimitive(args) {
  const object = BABYLON.MeshBuilder[`Create${args.type}`](args.name, {}, activeScene);
  if(args.physicsType === 'static'){
    object.physicsBody = new BABYLON.PhysicsAggregate(object, BABYLON.PhysicsShapeType.BOX, { mass: 1, restitution: 0 }, activeScene);
  }
  if(args.physicsType === 'dynamic'){
    object.physicsBody = new BABYLON.PhysicsAggregate(object, BABYLON.PhysicsShapeType.BOX, { mass: 1, restitution: 0 }, activeScene);
  }
  if(args.physicsType === 'kinematic'){
    object.physicsBody = new BABYLON.PhysicsAggregate(object, BABYLON.PhysicsShapeType.BOX, { mass: 1, restitution: 0 }, activeScene);
  }
  objects.set(args.name, object);
}

I’ve fixed the issue. I needed to use Physics.Aggregate

1 Like