Search code examples
godotgdscript

godot - how to change sprite of a child node dynamically


Screenshot of 'Tao' node:

enter image description here

I can't find a tutorial or a guide on how to change the sprite of a child node dynamically. I need to change the sprite of 'baba' which is a child of 'Tao.

Here's my code and it's not working:

var tao = Tao.instance()
var spr = str("res://assets/tao", i+1)
tao.get_child("baba") = load(spr)

Solution

  • I got the solution. Just wanna share.

    var tao = Tao.instance()
    var spr = str("res://assets/tao", i+1, ".png")
    tao.get_node("baba").get_node("itsura").texture = load(spr)