NullReferenceException

animation["idle"].layer = -1;

I am getting NullReferenceException at this line. Any suggestions plz.

My guess would be that animation[“idle”] returns null. Are you sure that animation exists? If not, there’s your problem!