Cannot read properties of undefined (reading 'on')

Hello! This is the first time I’ve used this forum. For my project I am trying to make it so that when the laser entity hits the “enemy ship” both the laser and the ship will disappear. For some reason I get an error when launching saying “Cannot read properties of undefined (reading ‘on’)”


In addition to this issue, I cannot make my particle systems look right. I have trouble making them go in the right direction and flow properly. The next problem I have is with my “entity spawner” entity. It does not work as intended. It is supposed to spawn multiple enemy ships but it spawns one and stops. And, when the ship flies away, the particle system does not move with it even though it is nested under the enemy ship in the template in the hierarchy. The link to my project is this: PlayCanvas | HTML5 Game Engine

Any help would be greatly appreciated!!!

I should also mention this issue takes place in the Level 1 Scene

Hey, The error is due to collision component missing in the entity and you are trying to access that.


The children entity named as Craft_SpeederC has the collision component so you should try adding the trigger script there.

2 Likes

That got rid of the error! However, I could not get the collision to properly fit on the enemy ship entity. I added a collision component and set it to mesh, but it said it would not work as expected.

edit: I didn’t understand what you meant at first. I added the trigger script to the Craft_SpeederC. This gets rid of the error, but I still don’t get the effect of it disappearing.

In addition, there seems to be issues with my enemy spawner script. It spawns one singular “enemy ship” then stops. It also leaves a particle system sitting by itself.

Hi @Michael_McPherson!

Please check the code of your trigger script.

Wrong:

this.entity.enabled = 0;

Correct:

this.entity.enabled = false;

It can also be a good option to destroy the entity:

this.entity.destroy();
1 Like