Is there a way to get every time activeState changes in anim graph?

Hi

I want a function to run every time my character’s anim.baseLayer.activeState changes but I couldn’t find if there is a way to do it

I came up with this

Char.prototype.update = function(dt) {
   if(this.previousAnimState !== this.entity.anim.baseLayer.activeState){
      this.testfunction(this.entity.anim.baseLayer.activeState);
      this.previousAnimState = this.entity.anim.baseLayer.activeState;
   }
};

but is there any other way?