0 votes

I have a custom resource called Item.How can i make an array of these items that i can edit in the inspector as well as through script?

in Engine by (22 points)

1 Answer

0 votes

I think if you are using GDscript, you will miss the ability to filter the type of resources in the inspector so I do not think you can say "only show Item resources", however you can at least make the structure you need work in the editor...

I assume you have your Item resource class defined in a .gd script, and I assume you have saved some instances of the resource (.tres extension) . I am assuming your resources are working correctly so you can open a resource in the editor and see it's properties in the Inspector panel.

In the scene that will hold the array, ensure you have the tool command as the first line of the script, then export an Array of Resources something like this

tool
extends Node # or whatever your scene extends 

export(Array, Resource) var test_array

When you have saved that and then re-select the scene in the editor (you may need to reload it), the tool command should cause the editor to display the test_array in the Inspector panel.

You can then set the size of the array which add rows in the inspector. For each row, you can then drag and drop your resource tres files from the FileSystem view in the editor into the "[empty]" resource field for each item on the array. When you click on a resource in the array the Inspector should show a panel with the properties of the resource, which you can edit.

It would be great if you could automatically set the array to expect each element to be an Item resource, but I am not aware of a way to do that in GDscript. If there is a way, hopefully somebody else can join in.

Since test_array just a regular Array, you can manage that in your scripts, like any other another array

by (478 points)
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.

Categories