onButtonStateChangedObservable triggers when no state changed?

Hi @RaananW! (Sorry I’ve been bugging you a lot lately :smiley: )

I’m trying to create an immersive pick-up and throw a mesh behavior. To do this I’ve converted the xr controller grip squeeze component into an rxjs observable subject so that I can use do stuff with it:

// check if squeeze is available
const squeeze = motionController.getComponentOfType('squeeze')
if (squeeze) {
  // check its state and handle state changes
  squeeze.onButtonStateChangedObservable.add(component => {
    this.signalHub.controllerComponentStream$.next({
      handedness: motionController.handedness,
      component: "squeeze",
      pressed: component.pressed,
      touched: component.touched
    })
  })
}

One of the things I did with the rxjs data stream is I output it to a GUI texture so that I could “console.log” the data while wearing the Oculus Quest.

What I noticed is that “most” of the time, pressing and releasing a component (such as trigger or squeeze) will produce 4 distinct messages:

{handedness: "left", component: "squeeze", pressed: false, touched: true}
{handedness: "left", component: "squeeze", pressed: true, touched: true}
{handedness: "left", component: "squeeze", pressed: false, touched: true}
{handedness: "left", component: "squeeze", pressed: false, touched: false}

This makes sense as the component is transitioning from lightly touched to fully pressed and then back again in reverse order.

However, once in a while I’ll see duplicate back to back messages such as:

{handedness: "left", component: "squeeze", pressed: true, touched: true}
{handedness: "left", component: "squeeze", pressed: true, touched: true}

Or

{handedness: "left", component: "squeeze", pressed:false, touched: true}
{handedness: "left", component: "squeeze", pressed:false, touched: true}

Where the exact same message is delivered more than once.

And lightly touching the squeeze will produce a stream of duplicate events like this image shows:

My question is, is this expected behavior?

Shouldn’t the onButtonStateChangedObservable produce distinct states from one invocation to the next?

You are forgetting one variable - the value. The button state also has a value between 0 and 1 (1 being 100% pressed, 0 being released). Pressed is roughly around 70% but is system-dependent.
So the value can change while pressed is still false.

Not a problem at all, I am happy XR is being used :slight_smile:

ahhhh… that makes sense. It’s how much I’m squeezing it. Thanks! Again!