I’m using a Node with metadata. This works great, but one of the metadata entries is a Vector2i array.
I’d like to resize this array from another Scene during runtime, but I can’t find a way how to do it.
I’d also like to modify a particular entry of the metadata array. But, again, I can’t find a way how to access a particular Array part. I tried various MyNodeWithMetadata.set_meta("local_d", ???) = my_value or MyNodeWithMetadata.set_meta("local_d")[0] = my_value
…and similar, but no luck.
I “solved” both problems by copying the whole array locally, modifying it and then copying it back like this:
var A = MyNodeWithMetadata.get_meta("local_c")
if some_condition: A.resize(new_size)
for s in A.size(): pass # some calculations
MyNodeWithMetadata.set_meta("local_c", A)
but this doesn’t look too efficient. Is there a better way to do it?
func _ready() -> void:
var value := [Vector2i(1, 1)]
$Node.set_meta("my_value", value)
$Node.get_meta("my_value").resize(5)
for i in $Node.get_meta("my_value").size():
$Node.get_meta("my_value")[i] = Vector2i(2, 2)
$Node.get_meta("my_value")[0] = Vector2i(0, 0)
$Node.get_meta("my_value").append(Vector2i(-1, -1))
and define a shortcut like var A = MyNodeWithMetadata.get_meta("local_c") is good when you need to do some complex calculations.
func _ready() -> void:
var value := [Vector2i(1, 1)]
$Node.set_meta("my_value", value)
var my_value = $Node.get_meta("my_value") # it's a reference
my_value.resize(5)
for i in my_value.size():
my_value[i] = Vector2i(2, 2)
my_value[0] = Vector2i(0, 0)
my_value.append(Vector2i(-1, -1))