So i need to change the mesh texture in-game, while user playing.
when i used this code, my object texture becomes pink (texture issue color).
Is there way to fix that?
var texture = ImageTexture.new()
var image = Image.new()
var mesh = block_drop_item.get_child(0).get_child(0)
if block_drop_item.item_name == "block_grass":
image.load("res://assets/blocks/grass.jpg")
if block_drop_item.item_name == "block_stone":
image.load("res://assets/blocks/stone.jpg")
texture.create_from_image(image)
mesh.material_override.albedo_texture = texture
also tried this way:
apply_texture(mesh, "res://assets/blocks/grass.jpg")
func apply_texture(mesh, texture_path):
var texture = ImageTexture.new()
var image = Image.new()
image.load(texture_path)
texture.create_from_image(image)
if mesh.material_override:
mesh.material_override.albedo_texture = texture
- i have checked the texture loader, and it's successfully loads the file, but seems that can't apply it to mesh.