0 votes

As the title states, I'm trying to define an array of colours in script and have them displayed in the scene editor but nothing is working. Normally I'd define each colour separate and then store them in an array from the _ready function but I'm trying to bypass this step since you can define arrays of items. What I'm seeing is that no matter what type I set the array as in script, I've still to edit the array, set its type and then manually set each item from the scene editor which is kind of tedious.

I've tried all of the following but to no avail

export (PoolColorArray) var cols = PoolColorArray([Color('hex'), ...])
export (ColorArray) var cols = ColorArray([Color('hex'), ...])
export (Array) var cols = [Color('hex'), ...]

When an attempt is made to get the value, an error is thrown

Invalid get index '0' (on base: 'Nil')

Hell, I've even tried to store the colour hexes in an array but I still have to manually edit it from the scene.

export (Array) var cols = ['hex', 'hex']

Oddly enough, a dictionary works, only partially, in that I can access the values in script later, but I still can't edit the colours from the scene editor.

export var cols = {Gray = Color('hex'), Black = Color('hex')}

So is what I'm asking possible at all?
Note: the above was tested in a daily build of v3a (#0e8db63).

in Engine by (124 points)

if you are looking for a way to change the color while the game is not running(aka in the editor itself) this tutorial might help:
its called a tool mode and it sorta runs in the editor itself

I know a way to have fancy editing in inspector but it requires relatively low level code to be written in your script.
The idea would be to use _get_property_list to create fake properties for every item in your array (using a for loop), and use _get and _set for edition to work on them. Then an extra property would be added which carries the actual array so that it doesnt slow the game due to editor code.
I've done this in C++ once so that I could have an array of resources in the inspector, but I dont have a GDScript example, I could try to write one if you want.

Actually I have tested this in 3.0 alpha 2:

export(PoolColorArray) var colors = PoolColorArray()

This gives you a property with a little arrow to click, then you can choose the size of the array and you can edit all the colors you want without having to set their type. What's the problem with this?

Please log in or register to answer this question.

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.