Transference

The idea with transference, is that we can learn empathy for one group. For example children can learn empathy for their pets, and that empathy will transfer to other children as well. Or people can learn empathy for family members and that will transfer to strangers.

For example see A STUDY OF THE TRANSFERENCE BETWEEN EMPATHY TOWARDSCOMPANION ANIMALS AND EMPATHY TOWARDSHUMANS IN CHILDREN by Mary A. Lind

"Transference is a phenomenon characterized by unconscious redirection of feelings from one person to another. One definition of transference is "the inappropriate repetition in the present of a relationship that was important in a person's childhood"." Wikipedia