How to change model's texture

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

Hi.
I want to change texture of my model using gdscript but dont know how to do it.
I have a little script below, which I put on my model (Spatial).
Using Godot 3.1.1.

func apply_texture(mesh_instance_node : MeshInstance, texture_path : String):
  var texture = ImageTexture.new()
  var image = Image.new()
  image.load(texture_path)
  texture.create_from_image(image)
  # next line doesnt work
  mesh_instance_node.material_override.albedo_texture = texture  
func _ready():
   # get MeshInstance named 'obu1'  (is this right way?)
   var mi = find_node("obu1");
   apply_texture(mi, "models/bg.png");