How to make a property that with dynamic size

Godot Version

4.4.1

Question

Hi, I’m making a game with a non-programmer friend, so I’m trying to make my the customization of everything through the export property with the @export annotation. Now I’m making an enemy patrol system and decided to use a NavigationAgent3D inside the Enemy.tscn with some Marker3D around the NavigationRegion3D in the Map.tscn. I made the enemy patrol with the points hardcoded, but I want to my friend to be able to place points inside the map and pass then to the enemy like you can put points on the Path3d like the image bellow:


How can I export something that I can dynamically add and delete items? I tried array and Dictionary but they do not look like that

1 Like

SOLUTION 1

Exporting an array of type [Marker3D] should give you an expandable list of marker3ds in the editor.

if you do:

@export var markers: Array[Marker3D];

you get this:


if you then increase the size you get the fields where you can pass Marker3Ds

This does not look the same as the way Path3D does it but could be useful depending on your usecase.

SOLUTION 2
If you are only interested in the positions then you could export an array of Vector3s:

@export var positions: Array[Vector3];

This is what it looks like:


in _ready you then need to call your_path.curve.add_point() for every point in your array to add them to the curve.

SOLUTION 3
If you want to make it even more similar to Path3D you can define your own resource like this:

extends Resource
class_name TestRes

@export var position: Vector3;
@export var out: Vector3;
@export var tilt: float;

and then export an array of your custom resource:

@export var markers: Array[TestRes];

This is what that looks like:

SOLUTION 4
You can just export a Curve3D this is the type that Path3D uses to store the points.

@export var curve: Curve3D;

This is what it looks like:


In your code you can then set your curve as the curve the path uses with:

your_path.curve = curve;

Exporting powerful tools for yourself and your designer is really a gamechanger!

3 Likes

What I wanted was solution 1. I mentioned the Curve3D just to point that you can dynamically add and remove items from the list/array. But I would like to also have the arrows to move items up and down without using the object Curve3d

yeah im not sure why Curve3D gets the arrows.
However you can reorder any of these solutions by draggin the ‘hamburger’ on the left

2 Likes