How to fix Uncaught TypeError: cannot read properties of null (Reading 'clone')

Hi @ssgrts,

I took a look at your project, and can point you in the right direction. The problem is that your Bullet (in the hierarchy) is enabled at app start. This means that your first bullet is cloned effectively and fired, but because you teleport it to the same spot as the original bullet, the collision logic you have destroys the original bullet (and the 2nd one you teleport there too, really).

Because of this, the 2nd time you fire, there is no longer a bullet in the hierarchy to clone for the script. The immediate fix, on my fork, was simple to disable the bullet in the editor. Luckily, your script is already enabling it when firing.

That being said, I see that your bullet is a template. You don’t even need to have it as a part of the initial scene and could instead simply instantiate the template. This will keep your scene clean and give you greater control of the entities that are spawned.

For more information about templates, check out this user-manual page explaining them:

or this forum post:

I hope this is helpful.

3 Likes