Add a check around this optional function

My game crashes here if I update phaser.js to a new version. It happens
when my game switches to another State object.