Invalid Object or string in operator ==

Im trying to make raycast for the player and an enemy with the script

if RayCast.is_colliding() and RayCast.get_collider() == player:
	kill()

however it doesnt work bcs of this error’

The best way I’d do this is to put the player into group “player” then I’d use this code:

if RayCast.is_colliding():
    var collider = RayCast.get_collider()
    if collider.is_in_group("player"):
        kill()

Is player valid at that point? It seems like player is not valid.

player is a @onready node for “CharacterBody2D”

Didnt work

Probably going to have to post your entire code. Along with your scene tree.

1 Like

Ill do it later. Mabye another day

Your player variable is a string instead of a node.

Maybe you defined player like so

@onready var player = "Player"
# A string, not a node named Player

@onready var player = $"Player" # fixed
# The $ will try to get the node named Player

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.