Cannot read properties of null (reading 'resource')

Help is greatly appreciated! I tried everything I knew to fix this issue but I’m having trouble.
Here is the editor:PlayCanvas | HTML5 Game Engine
The script name is InputHandler.
This is the script, but the issue is at the end

var InputHandler = pc.createScript('inputHandler');

// initialize code called once per entity
InputHandler.prototype.initialize = function() {

};

// update code called every frame
InputHandler.prototype.update = function(dt) {

 // Move Left when the A key is Pressed
    if (this.app.keyboard.isPressed(pc.KEY_A)) {
    this.entity.translate(0.1, 0, 0); 
    }

 // Move Right when the D key is Pressed
    if (this.app.keyboard.isPressed(pc.KEY_D)) {
    this.entity.translate(-0.1, 0, 0);
    }
 // Move Right when the D key is Pressed
    if (this.app.keyboard.isPressed(pc.KEY_W)) {
    this.entity.translate(0, 0, 0.1);
    }
    // Move Right when the D key is Pressed
    if (this.app.keyboard.isPressed(pc.KEY_S)) {
    this.entity.translate(0, 0, -0.1);
    }
if(this.app.keyboard.wasPressed(pc.KEY_SPACE))
 { var templateAsset = this.app.assets.find("PlayerLaser");
  var position = this.entity.getPosition(); var entity = new pc.Entity();
  var instance = templateAsset.resource.instantiate();
  this.app.root.addChild(entity);entity.translate(position.x-2, position.y, position.z); entity.addChild(instance); }};

( var instance = templateAsset.resource.instantiate():wink: is giving me the error. It kept saying this:
[InputHandler.js?id=110061170&branchId=db850bed-a8d9-4da1-88cc-0b60acd38da5:31]: Cannot read properties of null (reading ‘resource’)

TypeError: Cannot read properties of null (reading ‘resource’)

Hi @Bradley_Pelletier,

This variable templateAsset seems to be null, so most likely the following line fails to find the template you are looking for:

var templateAsset = this.app.assets.find("PlayerLaser");

I’ve checked your project and you don’t seem to have a template asset by that name:

image

1 Like

What should I do now?

I have tried to make a new template but nothing happens.