But then you'll have a list (I know it's a small list) in two places. You may not have to update it, but you might and forget about the second place.
For me, I'd do something like this:
(You can put it in a singleton and call it from anywhere etc etc)
extends Node2D
var layer = []
func _ready():
layer.append("")
for i in range(1, 21):
layer.append(ProjectSettings.get_setting("layer_names/2d_physics/layer_" + str(i)))
print(get_layer("units"))
print(get_layer("buildings"))
print(get_layer("projectiles"))
func get_layer(layer_name):
return layer.find(layer_name)
So that will printout:
1
2
3