"Cannot read property '_parent' of null"?

Got the error message after writing the code:
this.app.root.addChild(bullet);

bullet is a variable for the bullets fired from a gun. If you want a closer look at everything the code editor is shooting.js at
https://playcanvas.com/editor/code/539704?tabs=11418589,11376244

In a nutshell, in firebullets function,bullet is null so it can’t add it to the scene hierarchy.

You are also creating a new entity every frame in update.

In this scenario, you should be creating a new entity every time you fire and attach it to the scene hierarchy.

1 Like

Thanks! While you’re here, though, I noticed that after redoing the code, the bullet spawns at the origin and sits there for a second before despawning. How do I

  1. Set its position to the gun, and
  2. Move it forward?