Trying to bring an object into another scene

Godot Version

`4.2.2

Question

I’m trying to bring an object into another scene and I want the raycast to detect if it is an intractable object, if it is, i want it to prompt a message. The problem I’m having is its tell me raycast isn’t being declared, but I am declaring it.

this is my "interactable " script

class_name Interactable

@export var prompt_message = "Interactable"
#double check that its .tscn
var Orange = preload("res://orange.tscn")



func _ready():
	pass
		
		
		
		
func _input(event):

	if Input.is_action_just_pressed("my action "):
		var collider = raycast.get_collider()
		var instance = Orange.instantiate()
		add_child(instance)
			# Set the position of the object
		instance.position = self.position + Vector3(-15, -8, -10)
		if raycast and raycast.is_colliding():
		# Get the object the ray is colliding with
			if collider is Interactable:
				print("Found interactable object: ", collider.name)
			
			
		collider.prompt_message = "Press E to interact"
		


func _physics_process(delta):
	
	pass```


anything helps

Doesn’t seem like raycast is declared, there is no var raycast anywhere in this script.

1 Like

after adding a var raycast I’m getting an invalid call. it’s telling me my get collider is a nonexistent function. not sure how to go avout fixin this could you explain it so i could do it myself next time

Just adding var raycast will be a null variable, no functions will exist on it. What object are you trying to get? Can you share your scene tree?

If you are trying to get a child node named “Raycast3D” you can use the $ operator.

@onready var raycast = $Raycast3D
1 Like

thanks this sadly gave me an error. i think my idea just won’t work, i settled on using this code and it works

class_name Interactable

@export var prompt_message = "Interactable"


const water_height := 0.0

#double check that its .tscn
var Orange = preload("res://orange.tscn")




		
		
func _input(event):
	pass
		


func _physics_process(delta):
	if Input.is_action_just_pressed("my action "):
		var instance = Orange.instantiate()
		add_child(instance)
		var sprite = Sprite3D.new()
		sprite.position = Vector3(-15,-8,-10)
		sprite.texture = Orange
		
	```