• Godot HelpC++
  • Container for accessing mutable Vector<CustomStruct>

I will try to make it as concise as possible. I would like to have some kind of structure that provides key-based or index-based access to mutable Godot Vectors (or LocalVector) that hold a custom c++ struct. Adding and removing these vectors is not performance critical.

I've written this in raw c++ very easily with an std::unordered_map<int, std::vector<MyCustomStruct>> like so. But either i'm not good enough yet with the godot source/c++ or i've gotten blind over the hours, but all my attempts to implement this inside a custom godot module have failed.

I don't need a detailed explanation or code-answer. I really just need to be pointed in the right direction here.

My current and last thoughts on this would be either to use e.g. a Hashmap as the base container or just storing Vector<CustomStruct> Pointers instead?

So instead of my last approach Vector<Vector<CustomStruct>> which had the problem that the inner Vectors would always be constants, i would try something along the lines of this(?):
Vector<Vector<CustomStruct>*>

The overall Goal is to be able to do something like this container[i].push_back(...) or container[i].resize(..). If there are any question i'll answer asap. I'm really loosing it here, any help is Greatly appreciated!

  • xyz replied to this.

    xyz i ofc assume you mean std::unordered_map (using std::vector is not possible afaik see here)

    I did not find much usage of std::unordered_map in the source code, and especially not together with Godots Vector or LocalVector. I tried to google for it without success. My assumption is that mixing std structures together with godots own complex types can be a risky(?)

    will try in this special case though

    • xyz replied to this.