Why exporting variables instead of using unique names?

Basically title… we could use @onready var animation_player := %AnimationPlayer instead of exporting the animation player. Is there a good argument for one over the other?

The way i look at it is use case as both have their uses.
For example our player is already loaded into the scene so a reference can simply be an export variable hooked up in the inspector, However if we were instantiating our player at runtime then we would want to use an onready variable to ensure that the node has loaded and is ready to use.
This applies to the animation player as well as its already in the scene and so its ready to use and not needed to use the onready method.

You could potentially still use the onready method but there is possible a little more of an overhead as its checking to see if the node is ready when it doesnt need to but its not a great deal.

Hope this helps

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms