Skip to main content
Added unity tag
Link
Lasse
  • 3.2k
  • 2
  • 21
  • 31
Source Link
sigmaxf
  • 145
  • 1
  • 7

Processing Vs Memory Optimization

I'm creating a game with a lot of elements. Should I store all components that I'll eventually access on class variables (memory) or should I access them when running the script(processor)?

Example:

private SpriteRenderer sprite;

void Start () {
   sprite = GetComponent<SpriteRenderer>();
}

public void StartMovement()
{
    sprite.doSomething();
}

VS

void Start () {

}

public void StartMovement()
{
    GetComponent<SpriteRenderer>().doSomething();
}