Godot Version
godot 4
Question
I have a script that is handling item pickups in my game and I’m trying to assign a raycast3d in an export variable, which works, but everytime I try to use any of the ray’s functions, it gives a me a cannot call function on null value error. this also happens with all other nodes I try to assign to vars in this script, all are treated as null values despite being assigned. why might this be?
here’s the script in case that helps, I’m completely lost
extends Node3D
@export var velocity = 0
@export var Ray : RayCast3D
var Item
var holding = false
var pickUpCool = 10
var pickUpCoolMax = 10
var evidence_dict = {
"Stephanie's_Photos_House_": false,
"Polaroid": false
}
func _process(delta):
pickUpCool -= 1
if Input.is_action_just_pressed("Throw") && holding:
_throw()
if Input.is_action_pressed("Throw") && !holding && pickUpCool <= 0:
_pickUp()
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
func _throw():
pickUpCool = pickUpCoolMax
Item.freeze = false
Item.reparent(get_tree().get_root(), true)
Item.apply_impulse((Vector3(0,0,0) + -Item.transform.basis.z)* velocity, -Item.transform.basis.z)
Item.set_angular_velocity((Vector3(5,6,6) * -Item.transform.basis.z)* 3)
holding = false;