I've unfortunately fallen into the glitch scenario with Preston Garvey, described in a few other questions, where dialogue can't be initiated, and therefore he cannot be my companion. I don't have any viable pre-Castle mission saves to revert back to.
However, I've noticed that if he is nearby when doing weapon modifications, I'll still see a "Preston liked that" notification, so I'm seemingly still gaining affection with him. Doing this enough times should max out affection, so would his perk be obtainable in this glitched state? Perhaps by:
Can you get Preston Garvey's perk, even if he is dialog-glitched and cannot become your companion?
No he can't. Preston must be your active companion. Only then he can talk to you about your relationship. You still can get notifications like:
"Preston tolerates you"
"Preston admires you"
"Preston idolizes you"
But affection events are triggered only when character is your active companion.