Godot Version
4.1.1
Question
So I’m trying to make a basic interaction system prototype with a raycast 3d and a area3d. I’m just trying to detect the area with the raycast, then once its detected, allow the player to press the interact key and destroy the whole object. The hope was to just figure out if I can detect the object and execute the code, but when I do, the detection code freaks out because the thing its detecting is now a null instance, but its within an if statement that relies on the raycast colliding. I’m a little confused because shouldn’t the code within the if statement not run if there’s nothing to collide with? Why is it giving me errors that the object is a null instance when it shouldn’t even be running at all if that’s the case?
Here is the code , this is running within physics process on my player script. I’ve tried a couple different iterations with resources first but now I’m just using a simple object script that only has a is_interactable bool and the method explode() with queue.free() inside.
func _physics_process(delta):
if interactcast.is_colliding():
var obj = interactcast.get_collider()
if obj.is_in_group("object") and obj.is_interactable:
pickup_label.text = "Pick up " + obj.name
if Input.is_action_just_pressed("interact"):
obj.explode()
else:
pickup_label.text = ""
The label works fine, but once interact is pressed and the object deletes itself the error message is “Attempt to call function “is_in_group” in base “null instance” on a “null instance”” but if interactcast.is_colliding() returns false then shouldn’t that be irrelevant? Any insight on what I’m missing here would be greatly appreciated! Thank you for reading!