Custom type Pool Array

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

I would like to implement an array of [my custom type] objects. Is this possible in GDscript?

:bust_in_silhouette: Reply From: Zylann

In Godot 3, you cannot have one of the PoolXXXArray where XXX is a custom type. However, you can use untyped arrays to store any kind of object you want (those declared with []).

What if I create custom pool array, using GDNative?

Robotex | 2021-02-20 08:27

It’s the same in GDNative. You can’t have a PoolXXXArray of a custom type.
You can, however, implement a custom container in the language you chose, or use one from its standard library like std::vector<T>, but it won’t be exactly a PoolArray so it may have some specific behavior that you may have to learn. For example, PoolArrays can be passed cheaply by value since it does refcounting and CoW internally. std::vector does not do refcounting and does not do CoW. It can, however, be much faster for some use cases, and you can use it just fine within your own code.
But you won’t be able to pass these to Godot or GDScript, because Godot only supports its own types.

Zylann | 2021-02-20 15:06