understating memory usage - which would be better?

Hi, I’m developing for mobile - I have an animator controller and many different scripts that are triggering and setting values within this animator controller (player01’s anim controller)

right now i have it set up where each script has its own

private Animator anim;

referencing the player01 anim controller, but I’m wondering if this is a waste of memory - should I just have an AnimatorController script that contains a

public static animator anim;

? I’m trying to optimize my code, and am wondering which is better on performance.

Thanks for any insight

yes to the first one. no to the second. If you have that many scripts needing a reference to a character’s animator controller, you might try making a singleton. Which would be bizarre and most likely a nightmare.

You’re pre-optimizing in the wrong place. If you’re worried about wasting RAM, look into audio and texture import settings best practice for mobile.

as far as memory usage is concerned, Static objects are not instanced, therefor they are faster in code.


“So using the static keyword will make your code a bit faster since no object creation is involved.”

… Are bugs more common when using statics? Probably… so be careful not to misuse them