Interactable Object Not Interacting

Godot Version

4.5

Question

Hello! :smiley:

Im trying to make an interactable object in Godot 3D, following a tutorial. I’ve completed everything, including the animation in the animatable body 3D, but when I boot up the game it isnt working. (I have no warnings or errors, either)

I want to make E the way to interact, already set in my input map, and I want the interactable object to disappear and appear in the character’s inventory. I can’t figure out how to do that first part, though :,D

(Node 3D is my interactable area, its parented to the interactable object.)

extends Node3D

@onready var interact_label: Label = $Label
var current_interactions := []
var can_interact := true


func _input(event: InputEvent) -> void:
		if event.is_action_pressed("interact") and can_interact:
			if current_interactions:
				can_interact = false
				interact_label.hide()
			
				await current_interactions[0].interact.call()
			
				can_interact = true



func _process(_delta: float) -> void:
		if current_interactions and can_interact:
			current_interactions.sort_custom(_sort_by_nearest)
			if current_interactions[0].is_interactable:
				interact_label.text = current_interactions[0].interact_name
			else:
				interact_label.hide()
	
func _sort_by_nearest(area1, area2):
	var area1_dist = global_position.distance_to(area1.global_position)
	var area2_dist = global_position.distance_to(area2.global_position)
	return area1_dist < area2_dist
	
func _on_area_3d_area_entered(area: Area3D) -> void:
	current_interactions.push_back(area)


func _on_area_3d_area_exited(area: Area3D) -> void:
	current_interactions.erase(area)
		

This is the code for the animatablebody3d, which is a parent of the node3d

extends AnimatableBody3D

@onready var interactable: Area3D = $"Interactable Instance"

func _ready() -> void:
	interactable.interact = _on_interact
	
	
func _on_interact():
	if $AnimatableBody3D.frame == 0:
		$AnimatableBody3D.frame = 1
		interactable.is_interactable = false
		print("Memory")

The issue is that you can’t make E the way to interact? Or do you mean something else by “that first part”?

1 Like

when i press E the object isnt printing “Memory” or playing the animation to make it disappear

Is the area being added to the current_interactions array?

1 Like

THanks that was half the problem :slight_smile:

now when I click e to interact with my object, it kicks me out of the game and says ‘Invalid access to property or key ‘frame’ on a base object of type ‘null instance’.’

But im taking that as a good thing because now, at least most of my code is working :smiley:

extends AnimatableBody3D

@onready var interactable: Area3D = $Interact

func _ready() -> void:
	interactable.interact = _on_interact
	
	
func _on_interact():
	if $AnimatableBody3D.frame == 0:
		$AnimatableBody3D.frame = 1
		interactable.is_interactable = false
		print("Memory")

Your $AnimatableBody3D is not found, since this script extends AnimatableBody3D I’m assuming you mean to use the node the script is on, where $ looks for children of the attached node. If so you should use self.frame or just frame

1 Like

Okay, heres that part of the code now:

func _on_interact():
	if self.frame == 0:
		self.frame = 1
		interactable.is_interactable = false
		print("Memory")

Its now saying “_on_interact: Invalid access to property or key ‘frame’ on a base object of type ‘AnimatableBody3D (animatable_body_3d.gd)’

is there a different way i can just make the object disappear?

You can use the hide() function

Thank you!! :smiley:

It works now ^^ ( ijust need to figure out the labels and such, as well as shortening the collision area where you can interact but thats something i probably can do on my own ^^)

1 Like