Optimization on MoveToCursor()

Having the GetCoponent(), every time will click, is a good approach?
Should’t we get the NavMeshAgent component in the Start() method?

Thanks.

In the prototyping stage, it’s usually ok to use GetComponent often, but yes, when polishing and optimizing your game, you should cache references that

  • You know won’t be stale, i.e. other components on the same GameObject
  • That you’ll be calling more than twice in the script or that you’ll be calling every frame.

Thanks a lot :smiley:

Privacy & Terms