I have to explain this a lot during pugs and I'm astounded how many people don't know how to do it
To build Uber you must be less than 142.5% of your maximum potential hp
This means you do not need to lose your buff whilst building
Optimum health for building are as follows
Scout - Below 177
Soldier - Below 284
Demo - Below 248
https://wiki.teamfortress.com/wiki/%C3%9CberCharge
To work it out for any other class - 1.425 x (base health of chosen class)
Thanks