Optimized NPC AI handling?

Hello everyone! I am currently in the process of designing a high performance NPC system, with AI combat, movement, etc. Before I go extremely in-depth, I’ve got a question about movement which relates to server computing power versus client computing power. Should AIs be computed on the client closest to them, then their actions replicated via network ownership (tested this method, it works fine), or should they be entirely server-based and running off parallel lua? I’m trying to figure out which method is most performant, considering AIs would make up a large portion of the game, and have many advanced features, such as combat and communication.


You can run it on the closest client, but you should be careful to handle the case where the closest client changes (from one player to another). Parallel lua is a good idea but I would recommend you only use it for things which are Trivially Parallel, such as calls to certain helper functions that you know for sure are expensive. You’re very limited in what you’re allowed to do while in parallel code which isn’t made obvious by the documentation. Avoid it entirely if you don’t have any performance issues.

Also consider (as many horde shooter games do) that if AI are operating in clusters, it is not necessary for them all to be completely independent, it may be just as good for most to follow the lead of one.

1 Like
  1. Client side AI:
  • Pros: Reduced server load, lower latency
  • Cons: Potential inconsistency in NPC behavior across clients, security concerns
  1. Server side AI:
  • Pros: Consistent behavior across clients, increased security.
  • Cons: Increased server load, potential latency.

To make a choice which AI you should choose for the most performant method for your game, consider the scale of your NPC system, complexity of AI behavior, and server capacity. Server side computation is recommended for a large number of NPCs with advanced features, while client side computation can work for simpler systems with proper synchronization techniques. Benchmarking and profiling are crucial for evaluating performance and making an informed decision Xx

1 Like