Animator not working properly

My problem is a little complicated but I will try to explain it properly.
So the thing is I have a script that can swap the character controllers of 2 characters ( let’s call them player1 and player2) If you control “Player1” the script puts the player controller off from “player2” (where my scripting for my animations is).
Now I get a glitch if I run while swapping characters the running animation keeps playing on the other character instead of going to idle because it just stops the script and doesn’t update my speed parameters in the animator.
I know this explanation is weird but if you can help me I would be very thankful.

This script swaps character controllers:

My character controller script is big so this is just the animation scripting in an other script

Not sure I fully understand but if the problem is that after the swap you don’t get the final “tick” needed to leave the animator in the right state can you not just manually call the update() once when the switch happens after the switch has occurred but before leaving that switch function?