Improve hook mechanic
RavioliMavioli opened this issue · comments
@dfgworm By the way, the method that you use to cache nodes into variables is by using get: return node
instead of putting directly on to @onready var
. I would like to know why the getter method is the preferred way.
I would like to know why the getter method is the preferred way
One reason is the ease of transfering nodes around. If you just get it using @onready
, you won't be able to move the node during runtime without completely breaking all references in and out of this node.
Also there is the argument of error tolerance. In case of anything going wrong, active getter actually has a chance to fix itself.
I actually had a case in my project where @onready
did not work at all. I had to do some things in _ready
in one component, and @onready
of another component did not yet happen, so it still had some nulls when i needed it. It worked fine with active getters. Another way to fix that would be to defer _ready
code, but that could potentially cause other ordering issues.
All of this might be particularly relevant to your character selection mechanic.
In the end there is just no downside to doing it this way.
you use to cache nodes into variables is by using
get: return node
This is actually the opposite of caching, since i just get the node every time it is needed without saving it anywhere. I'd call it a statically typed shortcut.