Help with Draw() function

Godot Version

godot 4

Question

I’m trying to make a basic UI upgrade/skill tree where once you have bought an upgrade, it unlocks other upgrades and connects them by a line and or dashed line in my case. I have a global variable called str_bought which just holds a boolean of whether or not the first upgrade has been bought.

I thought using the _draw() function would work best but I don’t know how to continually check until the global variable str_bought is equal to true (the upgrade has been bought) and THEN only draw the lines

For more context, all nodes from the root node to each upgrade node is within the same scene tree.

Something quick and dirty would be having some skill tree manager/controller and then in its update method check if the variable is true. But I dont recommend this way.

What you should do instead, is whenever you ‘buy’ the skill, send out a signal (for example the pressed signal from a button) to the skill tree controller and have that then respond to the signal by drawing the line and enabling the next skill.

Can you give an example of how to do this in code, like the connection on the control node from the signal to the draw function?

have a button, go to the node tab and click on the pressed() item in the list there.
connect it with some name, like skill_bought. and select the skill tree controller as the script to connect it to.

Then in code:

func skill_bought() -> void:
    # TODO implement draw method here
    pass

Connecting signals, should be something you should already know if you are making something complex like a skill tree.
If you dont understand them I recommend looking at the docs for signals or looking on youtube for tutorials about godot signals