Gui create node from template at runtime (SOLVED)

Hi everyone,

Something is eluding me.

Can you create a node based on a template at runtime?

Thanks in advance!

2 Likes

You add it to your GUI scene, disable it with gui.set_enabled() on init(), then when you need to create a new instance of it, use gui.clone_tree() and then enable the cloned node.

4 Likes

Felt “hacky” to me, so i was wondering if there was a way of maintaining a library of template to create from.

But it works of course :slight_smile:

Thank you!

1 Like

Yeah, the process could perhaps be improved, but for now this is the recommended solution, and to be honest, it is unlikely that it will change anytime soon.

Count me in to see this become a useful feature in some future version. I was just learning about them and the first thing I thought of was build library of these and then call them dynamically from code. Will look into this workaround. Is there any side-effect danger of this approach (memory, etc.?) to keep in mind?

Nothing besides the fact that you have one instance hidden in your GUI scene that you use when you create new instances.

1 Like