Object detects some Area2d Nodes, but not all of them

Godot Version

4.4

Question

Hi, all. I’m still pretty new to Godot and I’ve been trying to make an inventory system as of late and have been getting some decent progress, but have run into some problems trying to implement some features.

The inventory system I have in mind is a simple drag and drop inventory system with the player being able to directly add an item to the slot by simply dragging the object there.

Because of this, the logic I had going forward was to have the slots in question have an Area2D Node that would be able to collide with the object and cause the object to delete itself from the scene.

And while I was able to get this function within the GridContainer itself, I’ve run across a problem where the object will only detect 1 or 2 of the Area2D Nodes.

The object is supposed to Queuefree once a collison is detected in its area. Here’s the script I have for the areaentered function:


func _on_area_2d_area_entered(area: Area2D = object) -> void:
	if area.area_entered:
		queue_free()

Here’s the script for the inventory slot area function:

func _on_area_2d_area_entered(area: Area2D) -> void:
	print('+1 item')

I have my inventory set up according to what I have in mind, but it may have issues with the collison placement, at least that’s my theory.

And my main setup for the main world, mostly barebones since it’s a test.

Any advice on how improve the collison detection would be appreciated, and any overall advice on how to better implement the mechanic would also be appreciated

Thank you very much for your time!

Rather than mixing control and node2d, you can use the controls mouse_entered/exited.

1 Like

I would have each item have the data that needs to be stored.

Texture, reference ect…

You can pick up the item, and you store which item you are carrying. When you go to drop in slot you communicate what item you are carrying, transfer the needed data, and then queue_free original item.

Your slot can have a texturerect that can be given the texture of item for display.

1 Like

I was trying that but I had a problem where the slot would only detect the mouse rather than the object being carried. Then I was trying to figure out how to make it so that when the platform detected a mouse being entered, it would get the node of the object and delete it from the scene, but I ran into a problem where the output said that the object value is null. This may be because the object doesn’t have a resource attached to it, but I’m not sure how to go about attaching the actual resource to the object so that it returns a node path that can be properly recognized and deleted.

It is hard to know what exactly is going on without seeing your code.

Here is one way to go about it.

Have a transport node.

Connect the mouse entered/exited signal from slot to get_item(slot: Slot) in your transport node.

In the transport node have variables that store the info from the item you need for the slot.

When the slot sends signal to get_item(slot) have a check, if item_stored == null: return
Then you would call slot.set_item(send needed info here)

In slots set_item(info) you would handle registering the info in the slot, setting up texture and such.

At the end of your get_item() in transport node, after you call slot, you would item_stored.queue_free() then make any associated var = null.

Also, how are you storing the item? You shouldn’t need to store the item instantiated, but rather just its file reference for if you need to instantiate it later and a texture to represent the item.

Example

var item_stored = res://some_scene.tscn
var texture = res://some_pic.png

1 Like