posted to: Coding the Coin

About the onready

Hi Nathan, Why do you exactly need the reference definition for the AnimationPlayer on this lesson? Couldn't you achieve the same result just using $AnimationPlayer in the _on_body_entered function instead? Regards.
  • Nathan Lovato replied

    There are two reasons we recommend to store node references in variables:

    1. At a glance, at the top of your class, you can see all the dependencies of the class. All the nodes that, if you change them, can break this code. The more complex your projects become, the more bugs it'll save you.
    2. Calling get_node() (or $) on the fly has a small performance cost. It's fine to do here and there, but if you get used to doing that everywhere, especially in process callbacks or loops, it will start to eat some of your CPU as your code grows.
    1 love