Anyway to access your Collision Layer names in Godot 3.0?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By avencherus

Playing around with the new layer naming. It’s nice for the UI, but in GDScript is there any way to set a mask using one of those assigned names?

Yeah, I’m also looking for a way to get layer name by it’s ID

Alexande Daubricourt | 2018-04-25 18:21

I haven’t been able to find any clean or built in way to access them. :confused:

If you need something, my current solution is use a dictionary to build a table out of the settings that maps the associated power of two to the layer name.

Though may want to reverse the key and value, depending on how you want to use it.

var mask_bit_to_name = {}

for i in range(1, 21):
	var layer_name = ProjectSettings.get_setting(
		str("layer_names/2d_physics/layer_", i))
	if(not layer_name): layer_name = str("Layer ", i)

	mask_bit_to_name[pow(2, i-1)] = layer_name

avencherus | 2018-04-26 01:56