Certain variables &result.entity are undefined when they shouldn't be

As I am continuing to work with ETA, I have run into a problem. On the UI 2D Screen, I have a button called Ruler_Button. When this button is clicked, the texture is supposed to switch to one with a cyan outline, indicating that it has been selected. At the same time, I am using rigidbody.raycastFirst() to select tiles in the scene.

The problem is that this is causing some sort of conflict. If the Ruler_Button is not in “front” of any tiles, the button selection works fine. But if the button is in “front” of a tile, the button behavior becomes erratic. For example, the global boolean variable rulerActive that controls the button’s texture is somehow gets undefined (according to the console log). Presumably as a result, the texture does not change, even when the button is clicked. Also, the tile behind the button is selected as well, even though the button should be capturing the mouse input and preventing the raycast from reaching the tile. This behavior seems to persist whether or not the button has collision and rigid body components.

The tile selection functionality also depends on the rulerActive variable, so I imagine that whatever mistake I made in the ruler.js file (ruler.js lines 4, 45, & 50) is the reason why the tile selection (itemPicker.js lines 80-89) isn’t working, either.

Also, sometimes after selecting multiple tiles, the following TypeError occurs, and the tile refuses to change material. Is the sources tab stating that pickedEntity.model is undefined? It seems like a lot of my problems have to do with defining variables and such.

Let me know if my question is missing anything.

EDIT: Basically I want for the button and the tiles to work independently of each other, regardless of whether or not there is a tile “behind” the button. The button should take precedent if intersects anything.

EDIT 2: Upon further testing and reflection, the real problem is that certain fields are not being populated correctly. The title of this post has been changed to reflect this.

EDIT 3: I added a bit of debugging script, and it turns out that UI buttons are being accidentally clicked when the cursor is nowhere near them. The issue in question has been migrated to here: