Creating a spatialmaterial but I cant seem to set a texture to it in code.

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

Im creating a voxel block and every time I set a texture it just produces a black square but if I set a colour without a texture it renders the colour, any help on how to resolve this, thank you.

here is the code`
extends Spatial

export (Resource) onready var default_texture
var mesh = Mesh.new()
var mat = SpatialMaterial.new()
var color = Color(0.0, 1, 0.0)
var index = 0
var UVs = PoolVector2Array(
[Vector2(0,0),#0 Done
Vector2(1,0),#1 Done
Vector2(1,1),#2 Done
Vector2(0,1),#3 Done
Vector2(1,0),#4 Done
Vector2(0,0),#5 Done
Vector2(1,1),#6 Done
Vector2(0,0)#7 Done
]
)
var voxel_verts = PoolVector3Array( [
Vector3(0,0,0),#0
Vector3(1,0,0),#1
Vector3(1,1,0),#2
Vector3(0,1,0),#3
Vector3(0,0,-1),#4
Vector3(1,0,-1),#5
Vector3(1,1,-1),#6
Vector3(0,1,-1)#7
] )
var voxel_tris = [
0,3,1,1,3,2]

func _ready():

mat.albedo_color = color
mat.set_texture(0,default_texture)
var st = SurfaceTool.new()
st.begin(Mesh.PRIMITIVE_TRIANGLES)
st.set_material(mat)

for v in voxel_tris.size():
		index = v
		st.add_color(color)
		
		st.add_vertex(voxel_verts[voxel_tris[index]])
		st.generate_normals()
		st.add_uv(UVs[voxel_tris[index]])
st.commit(mesh)

$MeshInstance.mesh = mesh

`