I’m working on a pathfinding algorithm (for my own learning enjoyment) and so far I’ve been able to create a square grid. Which is excellent. But now I’m wondering how to have each “node” on the grid hold a couple of pieces of information (for example, speed and cost, etc) at each grid cell.
In theory, I want some sort of container that holds these pieces of information at each grid cell correct? I’ve come up with several ideas, but the first one I thought of seems like it may not be the best. That is, to create empty game objects at each cell, and attach a script to each empty gameobject that holds the variables I need. However, it seems to me that the component lookup for each script on every cell might be slow compared to other methods?
My second thought is to learn how to use structs (first lol). And then have the information I want at each cell to be within the struct. And create an array of structs. Not sure exactly how that would work.
So all this being said, what is the best “performance critical” way to store information in a node, and then retrieve it as fast as possible as well. I know what I’m asking is somewhat involved, but I’m looking for how people generally do this when they’re looking for performance.