Godot MeshLibrary interactable objects not working

Godot Version

4.3.stable

Question

Hi, I'm making a game with an object called a chest which opens a GUI when clicked. However, I'm having trouble getting it to do that. Right now, the chest is in a MeshLibrary with a MeshInstance containing a CollisionShape3D(chest collision), a Sprite2D(chest GUI), and an Area3D(click detection) with a ColliswionShape3D(area3D collision) inside. Can anyone help?

It depends somewhat on what you’d like the GUI to do. Is it full-screen? Floating in the air above the chest? An image or a storyboard would be useful here.

If you want something that appears “on the screen” as opposed to floating in the scene as part of the world, the easiest thing to do is probably make a “chest GUI” scene with UI nodes (labels, buttons, containers…). Add it to your game scene with visibility set to false (close the eye for the scene in the Scene panel).

When the player clicks on your chest, call .show() on the chest GUI scene.

1 Like

OK, thanks, but should I add that in the MeshLibrary for my chest, or in my main game scene?

Personally, I’d be inclined to put it in the main game scene, so you can reuse it if you have multiple chests or other searchable things.

When a chest is opened, maybe have it call a function like:

# assumed hierarchy:
# ChestGUI - panel or something
#    Title - label
#    GoldCount - label
#    Items - GridContainer
#        - add item icons here...


func activate_chest_gui(chest_data: Dictionary):
    $ChestGUI.show()
    $ChestGUI/Title.text = chest_data["name"]
    $ChestGUI/GoldCount.text = "%dg" % chest_data["gold"]
    for items in chest_data["items"]:
        add_item_to_chest_gui(item)
1 Like

Thanks for your help :slight_smile:

1 Like