I'm trying to create a procedural generated level. Around each generated room, I want to a create a number of Blocks/Cubes working as walls. This already works. For Debug-Purposes I wanted to give each Wall-Segment a different color, based on it's position around the room. However, in the end, they all look the same.
extends Spatial
...
var segment = preload("res://WallSegment.tscn")
var width = 4.0
var length = 4.0
func _add_segment(x, z, rotate = false):
var new_segment = segment.instance()
var meshInstance = new_segment.get_node("MeshInstance")
var mat=meshInstance.get_surface_material(0)
mat.albedo_color = Color(float(x/length), 0, float(z/width), 1.0)
meshInstance.set_surface_material(0,mat)
...
Any Idea what the problem could be?