There are many ways of doing this. Vassili offers one good approach. Another approach is to have a Root Service on your Behavior Tree that modifies your NPC’s behavior (Idle, work, walk etc). Inside this service you can first check the distance between the Player and the NPC and if the distance is less than “MaxActiveDistance”, then continue (True), but if this is False (NPC is farther than MaxActiveDistance" then do nothing (False).
This effectively stops your BT from executing past your root service, effectively “Freezing” your NPC in place. You can take it further and also make the NPC invisible to save rendering cost. This is good because it keeps all your NPCs in the world frozen, but still keeps their BTs ticking and checking distance. A more performant solution is to destroy the actor altogether when far and respawn when close. This approach is more performant but harder because you will have to save each NPC’s state and restore it when Player gets close.
Ultimately you should try a few different approaches and come up with a custom solution that works for your game.
Hope this helps!