It's a calorie surplus, whether from sugar, fats ,or even protein. The quality of your diet can change the ability to process calories somewhat, but the bottom line is that for purposes of gaining weight, it's all about calories in minus calories out. Exercise, nutrition, etc, are all ways of modifying these two quantities.