title: Calling this.scene.restart() in Phaser 3 TypeError: this.body is undefined
body: <p>I'm trying to restart the game scene in Phaser 3, and when calling this.scene.restart I get an error saying "this.body is undefined" at setVelocityX in the phaser.js script (line 169442 in the unminified script if that helps)</p>
  
  <p>I am using the latest version of Phaser, v3.19.0.
  The hitEnemy function is called when the player sprite collides with the enemy, which pauses the physics and sets gameOver to true. In the update() function I'm checking if gameOver is true, as well as if the "R" key is pressed, in which case scene.restart() is called
  Below is part of my code:</p>
  
  <pre><code>var config = {
      scene: 'scene1',
      type: Phaser.AUTO,
      scene: 'scene1',
      width: 1080,
      height: 890,
      pixelArt: true,
      physics: {
          default: 'arcade',
          arcade: {
              gravity: {
                  y: 500
              },
              debug: true
          }
      },
      scene: {
          preload: preload,
          create: create,
          update: updateDirect
      }
      };
     function preload() {
          var progressBar = this.add.graphics();
          var progressBox = this.add.graphics();
          progressBox.fillStyle(0x222222, 0.8);
          progressBox.fillRect(380, 270, 320, 50);
  
          var width = this.cameras.main.width;
          var height = this.cameras.main.height;
          var loadingText = this.make.text({
              x: width / 2,
              y: height / 2 - 50,
              text: 'Loading...',
              style: {
                  font: '20px monospace',
                  fill: '#ffffff'
              }
          });
          loadingText.setOrigin(0.5, 0.5);
  
          var percentText = this.make.text({
          x: width / 2,
          y: height / 2 - 5,
          text: '0%',
          style: {
              font: '18px monospace',
              fill: '#ffffff'
              }
          });
          percentText.setOrigin(0.5, 0.5);
  
          var assetText = this.make.text({
              x: width / 2,
              y: height / 2 + 50,
              text: '',
              style: {
                  font: '18px monospace',
                  fill: '#ffffff'
              }
          });
          assetText.setOrigin(0.5, 0.5);
  
          this.load.image('bgtile', 'bgtile.jpg');
          this.load.image('background', 'assets/lava/background2.png');
          this.load.image('platformdefault', 'assets/lava/lavaplatform.png');
          this.load.image('platform400', 'assets/lava/platform4002.png');
          this.load.image('platform500', 'assets/lava/platform500.png');
          this.load.image('platform300', 'assets/lava/platform300.png');
          this.load.image('platform200', 'assets/lava/platform200.png');
          this.load.image('platform100', 'assets/lava/platform100.png');
  
          this.load.image('stopper', 'assets/lava/stopper.png');
          this.load.image('sign', 'assets/lava/sign2.png');
  
          this.load.image('enemy', 'assets/lava/enemy2.png');
          this.load.spritesheet('dude', 'assets/sprites/dude.png', {
              frameWidth: 32,
              frameHeight: 48
          });
  
          this.load.spritesheet('lavafloor', 'assets/lava/lavasprite.png', {
              frameWidth: 320,
              frameHeight: 100
          });
          //scary flash ooo
          flash = this.load.image('flash', 'assets/images/blue-flash.png');
          this.load.image('floor', 'assets/lava/floor.png');
  
          //audio
          this.load.audio('fantastic', 'assets/audio/fantastic.mp3');
          this.load.audio('wait', 'assets/audio/wait.mp3');
          this.load.audio('ward', 'assets/audio/ward.mp3');
          this.load.audio('whisper1', 'assets/audio/whisper1.mp3');
          this.load.audio('whisper2', 'assets/audio/whisper2.mp3');
          this.load.audio('whisper3', 'assets/audio/whisper3.mp3');
          this.load.audio('whisper4', 'assets/audio/whisper4.mp3');
          this.load.audio('hey', 'assets/audio/hey.mp3');
  
      //  this.load.video('spider', 'assets/video/spider.mp4');
      //  this.load.video('skull', 'assets/video/skull.mp4');
  
          this.load.on('progress', function (value) {
              progressBar.clear();
              progressBar.fillStyle(0xffffff, 1);
              progressBar.fillRect(390, 280, 300 * value, 30);
              percentText.setText(parseInt(value * 100) + '%');
          });
  
          this.load.on('fileprogress', function (file) {
          //  console.log(file.src);
              assetText.setText('Loading asset: ' + file.key);
          });
  
          this.load.on('complete', function () {
              progressBar.destroy();
              progressBox.destroy();          
              loadingText.destroy();
              percentText.destroy();
              assetText.destroy();
          });
      }
  
  
      function create() {
          bgtile = this.add.image(400, 300, 'background');
          this.cameras.main.setBounds(0, 0, 10392, 100);
          this.physics.world.setBounds(0, 0, 10392, 710);
  
          cameraHeight = this.cameras.height;
          cameraWidth = this.cameras.width;
          platforms = this.physics.add.staticGroup();
          stoppers = this.physics.add.staticGroup();
  
          var floor = platforms.create(400, 775, 'floor');
  
          sign = this.add.image(400, 560, 'sign').setScale(0.06);
  
          platform1 = createPlatform400(400, 600);
          platform2 = createPlatform100(1100, 200);
          platform3 = createPlatform300(700,500);
          platform4 = createPlatform200(900, 350);
          platform5 = createPlatform200(1325, 317);
          platform6 = createPlatform100(1605, 358);
  
          fantastic = this.sound.add('fantastic', { loop: false, volume: 0.2 });
          wait = this.sound.add('wait', { loop: true, volume: 0.3 });
          ward = this.sound.add('ward', { loop: true, volume: 0.2 });
          whisper1 = this.sound.add('whisper1', { loop: false, volume: 0.1 });
          whisper2 = this.sound.add('whisper2', { loop: false, volume: 0.2 });
          whisper3 = this.sound.add('whisper3', { loop: false, volume: 0.2 });
          whisper4 = this.sound.add('whisper4', { loop: false, volume: 0.2 });
          hey = this.sound.add('hey', {loop: true, volume: 0.2})
  
          whisper2.play();
          whisper2.on('complete', function(){
              fantastic.play();
          });
          fantastic.on('complete', function(){
              hey.play();
          });
  
          var frameNames = this.anims.generateFrameNames('lavafloor', {
                       start: 1, end: 4
          });
  
          this.anims.create({ key: 'lavaAnim', frames: frameNames, frameRate: 4, repeat: -1 });
  
          //player anims
          this.anims.create({
              key: 'left',
              frames: this.anims.generateFrameNumbers('dude', {
                  start: 0,
                  end: 3
              }),
              //frames refer to spritesheet frames, between 0 and 3 it will be left facing
              frameRate: 10, //10 fps
              repeat: -1 //stop animation
          });
          this.anims.create({
              key: 'turn',
              frames: [{
                  key: 'dude',
                  frame: 4
              }],
              frameRate: 20
          });
          this.anims.create({
              key: 'right',
              frames: this.anims.generateFrameNumbers('dude', {
                  start: 5,
                  end: 8
              }),
              frameRate: 10,
              repeat: -1
          });
  
          physics = this.physics; //get the reference to physics to create lava and enemies or platforms
  
          dude = this.physics.add.sprite(0, 100, 'dude').setScale(1.5);
          createLava(1274, 760);//add 320 to x for continuous lava
          createLava(2000, 760); 
  
  
          enemies = this.physics.add.group();
          spawnEnemy(platform3);
          wasd = this.input.keyboard.addKeys({
              up: Phaser.Input.Keyboard.KeyCodes.W,
              down: Phaser.Input.Keyboard.KeyCodes.S,
              left: Phaser.Input.Keyboard.KeyCodes.A,
              right: Phaser.Input.Keyboard.KeyCodes.D,
              space: Phaser.Input.Keyboard.KeyCodes.SPACE,
              restart: Phaser.Input.Keyboard.KeyCodes.R,
              pause: Phaser.Input.Keyboard.KeyCodes.P,
              action: Phaser.Input.Keyboard.KeyCodes.F
          });
  
          dude.body.setGravityY(800);
          dude.setCollideWorldBounds(true); //prevent running outside game window
  
          this.cameras.main.startFollow(dude, true, 0.08, 0.08);
          this.cameras.main.setZoom(1);
          this.physics.add.collider(dude, platforms);
  
          this.physics.add.collider(enemies, stoppers, hitStopper, null, this);
          this.physics.add.overlap(dude, sign, showText, null, this);
  
          this.physics.add.collider(enemies, platforms);
          this.physics.add.collider(dude, enemies, hitEnemy, null, this);
  
          onScreenText = this.add.text(16, 16, '', {
              fontSize: '32px',
              fill: '#fff'
          });
          playerPosText = this.add.text(dude.x+300, 16, '', {
              fontSize: '32px',
              fill: '#fff'
          });
  
          playerPosText.setScrollFactor(0);
      }
      function hitEnemy(dude, enemies) {
          this.physics.pause();
          dude.setTint(0xff0000);
          dude.anims.play('turn');
          gameOver = true;
  
      }
  
      function updateDirect() {
          playerPosText.setText('X: ' + parseInt(dude.x) + ' ' + 'Y: ' + parseInt(dude.y));
          if ((dude.x &gt;= 380 &amp;&amp; dude.x &lt;= 430) &amp;&amp; dude.y == 544) {
              showText("test");
          } else {
              showText('');
          }
  
          if(gameOver){
              showText("You died\nPress R to restart");
              if(wasd.restart.isDown){
                  this.scene.restart();
                  gameOver = false;
              }
          }
      }
  </code></pre>
  
  <p>I have used this in a project mostly based on the tutorial example, where it worked fine, and I'm using the same code here. I am very new to Phaser and game development in general, so any help would be greatly appreciated.
  Thank you</p>