+1 vote

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

in Engine by (70 points)

1 Answer

+1 vote

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 []).

by (27,666 points)

What if I create custom pool array, using GDNative?

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.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.