Scaling mesh causing texture to stretch (Is my script working right?)

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By KurtBlissZ
tool
extends MeshInstance

export(Vector3) var repeat: Vector3 = Vector3(1,1,1) setget set_repeat
var my_mesh: Mesh = get_mesh()
var sm: SpatialMaterial = my_mesh.surface_get_material(0) 
var prev_scale

func _ready():
	update_uv1_scale()

func _process(_delta):
	if prev_scale == null:
		prev_scale = scale
	else:
		if prev_scale != scale:
			update_uv1_scale()
			prev_scale = scale

func update_uv1_scale():
	sm.uv1_scale = scale * repeat

func set_repeat(vector: Vector3):
	repeat = vector
	update_uv1_scale()

It seems to be working, just unsure… Also there a way to callback a function whenever the scale is changed or would I just have to do what I’m doing now?

Edit: Purpose of this is trying to prevent lag, and making different sizes walls is getting annoying when you keep haing to uv1 them lol