Heading bug does not align with compass heading when HDG knob is pressed. Cessna 172 - G1000

Looks like the gyro drift autocalibration only works in flight. On the runway and before syncing heading you need to press D for 0 drift error. I have set a button for this in my joystick and it solved the problem.