Why am I getting a null value error on raycast?

Godot Version

godot 4

Question

I’m confused as to why this is returning the following error:

“Cannot call method ‘is_colliding’ on a null value”

func _pickUp():
	if Ray.is_colliding():
		var obj = Ray.get_collider();
		if (obj.is_in_group("ItemPickups")):
			Item = obj
			Item.reparent(self, true)
			Item.global_position = global_position
			Item.global_rotation = global_rotation
			Item.freeze = true
			holding = true;
			pickUpCool = pickUpCoolMax
		elif (obj.is_in_group("EvidencePickups")):
			if (evidence_dict.has(obj.name)):
				evidence_dict[obj.name] = true
				obj.queue_free()
				pickUpCool = pickUpCoolMax

What is Ray?

2 Likes

As @soapspangledgames noticed, if Ray is a variable, then most likely you forgot to assign a value to that reference, hence during runtime it is null and you cannot call a method on a null value.

1 Like

I appologize for the lack of clarity. Ray is a raycast which I have assigned via @export within the player scene, which I have placed in my level

Maybe the player instance in your level has it’s Ray export un-set.

2 Likes

just checked, it’s not that.

Could you paste the rest of your player script and show it’s properties in the Inspector?