Should I use a Node per item or a complicated nested array for items?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By ObsidianWhisper

I’m trying to figure out which would be the most efficient. I tried to look it up and found some stuff that was a little over my head, but boiled down to a script is lighter than a node in some cases. I’m in the planning stage of something akin to Cataclysm, and I’m trying to decide how I want to implement items. Be that in inventories or on the ground.

My current ideas are either using a Node2D with a small sprite as a child and a script holding the item info.

Or creating a complicated nested array that stores a tilemap coordinate, an array of items on that coordinate, each having either an array or dictionary containing the item information, and lastly the combined mass of all the items stored up next to the coordinates. Then I use the tilemap to project the latest item placed at those coordinates.

The array sounds like a nightmare to code around, but I also think in the long run it’ll be less taxing than a few hundred sprites sitting on top of one another and a node tree a mile long. That said, those individual nodes would only be accessed by proximity, while the entire massive array would be accessed every time the player moved, searching the top of the array for any coordinates that are within reach.

I’m still leaning towards the array though. Am I going in the right direction? Or is there a better way of implementing this that I’m oblivious of?

1 Like
:bust_in_silhouette: Reply From: Brightlight studios

Hello there, there is a node called grid container add all your items as a child of that node to organize your inventory, each item should have a script with it’s info and whatsoever with sprites and whatnot, if you need anything else lemme know, hope this helps

That would work as an option for inventory UI, but I don’t see how it would help with managing many items on the ground.

I think I’m going to go with a hybrid of my two options. I’ll have a quick reference array of the coordinates and “pile” nodes. The nodes will hold an array of the items on that spot and manage space capacity. I’ll be using a Tilemap in conjunction so that I can update the cell’s id instead of using sprites. This has the added benefit of meaning I can simply check my surroundings each move for a tile that isn’t -1, instead of having to search an array every move if one is near me.

Thank you for your suggestion just the same. I’ll probably do something like that when I get around to UI implementation.

ObsidianWhisper | 2020-09-26 03:19

Okay then good luck with your project

Brightlight studios | 2020-09-26 18:12

1 Like