|
|
|
|
|
by strictfp
1416 days ago
|
|
How do you people feel about the Godot object and lifetime model? I found it hard to test my code because of how objects are tied to the tree, that emulating the tree isn't easy during testing, and that initialization during live use is different than if you instantiate manually, making it hard to rely on a constructor, since you might not be able to use it live. I can't remember the exact details around this, since I only used Godot for a couple of jams and the last time was a year ago. But I was wondering if others have had the same reaction, perhaps this could be fixed? I love the engine in general, but this thing irked me. |
|
The tree turns out to be a great place to keep things, and you get several levels of control. Here’s how I think about it now.
`_init`: constructor. I usually use this to create dynamic child nodes
`_enter_tree`: now we have a parent; subscribe to signals, copy initial config, etc
`_ready`: I can be sure that all child nodes have called _ready, so anything I depend on there is… er, ready
`_exit_tree`: cleanup, especially anything we did with the parent and other ancestors. usually symmetric to `_enter_tree` if I’m using them
I just did a find all in my biggest recent project, and I never actually use `queue_free` or `free` for explicit memory management. Most of the times when I’ve thought I needed to, I actually was creating a bug