How to remove onPointerObservable

Hello,
I am facing issue with removing observable. This is what i have tried
var onPointerPick = function(evt){
if(evt.pickInfo.hit && (evt.pickInfo.pickedMesh)){
console.log(evt.pickInfo.pickedMesh.name);
var mat = new BABYLON.StandardMaterial(“mat”, scene);
mat.diffuseColor = new BABYLON.Color3(1, 1, 0);
evt.pickInfo.pickedMesh.material = mat;
clickedArr.push(evt.pickInfo.pickedMesh.name);
function getUnique(array){
var uniqueArray = ;
// Loop through array values
for(i=0; i < array.length; i++){
if(uniqueArray.indexOf(array[i]) === -1) {
uniqueArray.push(array[i]);
}
}
return uniqueArray;
}
var uniqueNames = getUnique(clickedArr);
localStorage.setItem(“ClickedSaved”,uniqueNames);
}
}
observer = scene.onPointerObservable.add(onPointerPick, BABYLON.PointerEventTypes.POINTERPICK);
for removal:
scene.onPointerObservable.remove(observer);
scene.onPointerObservable.removeCallback(onPointerPick);
not working.
Please help with this.

Can you reproduce the problem in a playground using a simplified version of your app? This makes it easier for someone to help.