Cannot change object location with raycast

Godot Version

v4.2.2.stable.official [15073afe3]

Question

So basically, if the raycast distance is close enough and it hits a object with the variable isobject = true, when you press e, it should move to your hand position(a node 3d). however, it doesn’t work but the game opens just fine. only warnings.

Pick-up system

extends Node3D
@onready var raycast = $"../Head/Camera3D/RayCast3D"
@onready var detectobject = raycast.detectobject
@onready var colliderparent = raycast.colliderparent
var handposition = Vector3(0.137, 0.099, -0.34)

# Called when the node enters the scene tree for the first time.
func _ready():
	pass # Replace with function body.


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta):
	if Input.is_action_just_pressed("e") and detectobject == true:
			colliderparent.position = Vector3(0.137, 0.099, -0.34)

Raycast

extends RayCast3D

var colliderparent
var detectobject
@export var detectdistance = 1.0
@onready var label = $"../../../../Ui/Label"
@onready var hand = $"../../../Hand"

# Called when the node enters the scene tree for the first time.
func _ready():
	label.text = str("")


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta):
	if is_colliding():
		var origin = global_transform.origin
		
		var collisionpoint = get_collision_point()
		
		var collisiondistance = origin.distance_to(collisionpoint)
		
		var collider = get_collider()
		
		var colliderparent = collider.get_parent()
		
		if colliderparent.has_method("get"):
			var isobject = colliderparent.get("isobject")
			var objectname = colliderparent.get("objectname")
			if isobject == true and collisiondistance < detectdistance:
				var detectobject = true
				label.text = str(objectname)
			else:
				var detectobject = false
				label.text = str("")

When code isn’t behaving the way you expect, you want to figure out where it’s going wrong. There are two very common ways you can do this:

  • You can insert print statements into the code and see which do and don’t get printed when you run it. So for example a print statement after checking if the collider’s parent has “get” will tell you whether or not you are ever getting into that block. Then a print statement inside your other if will tell you if you’re getting in there. You can also use that to print out other diagnostic information to help you understand what is happening and what is not.
  • You can use the debugger and set breakpoints and step through the code as it executes line-by-line to examine the states of your variables and see where the code is going.