Randomly Not Detecting Key Press

You are destroying the Entity that has the laserTest script attached and laserTest does it itself inside the raycastFirst callback. Basically laserTest performs a raycast, the raycast hits the Entity with the laserTest script and you call result.entity.destroy which destroys the Entity.

I found all that out by adding a ‘destroy’ method to your laserTest script while the game was running and put a breakpoint inside the destroy method to see where the destruction came from.

You probably don’t want the raycasting to hit the laserTest entity itself, so you could try adding some initial offset to the origin of the raycast so it always starts outside the Entity.

2 Likes