Unity 5.3 WebGL StateMachineBehaviours not executing.

I just updated to Unity 5.3, and decided to update one of the games on my website to the new WebGL build. When I tested the game, some of the functionality didn’t execute. After a lot of debugging I narrowed it down to the functionality inside the StateMachineBehaviour scripts(its a 2D game).

for example: If I make a behaviour like this and attach it to an animation, then the object is destroyed while playing it as a standalone build or in the editor. But if I export it as a WebGL build the object isn’t destroyed after the animation has finished playing.

override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)

Has anyone else experienced this, if so then I guess it needs to be reported as a bug.

EDIT: I have been in contact with the Unity bug report team, and I just recieved the following message:


We have been able to reproduce this bug and have sent it for resolution with our developers.

We highly appreciate your contribution. If you have further questions, feel free to contact us.


Hi! I faced the same problem with StateMachineBehaviour in my project. I noticed that in WebGL you can avoid this bug by switching off “Code Stripping” option on PlayerSettings. This helped me.

I faced same bug but on IOs. I found several options, that can be used right now:

  1. Disable “Code stripping” in player settings, as already proposed by Max Pushkarev
  2. You can install patched Unity 5.3.1p3 or newer. Bad news - it is said, that patches don’t work for WebGl
  3. Downgrade. See bugs below. It is said that bug is not reproducable on some 5.2.x versions of Unity


Unity Issue Tracker - [WebGL] StateMachineBehaviours not executing Unity Issue Tracker - [Stripping] StateMachineBehaviour overrides not called on iOS

PS Bug will be fixed in Unity 5.4. But it’s release date is march 16, 2016. So it is a long wait. I’m using 5.3.1p4 right now and for my IOS build all is good