I’ve read a lot of articles discussing NPC optimization and one common topic in that discussion is whether to handle the animation on the server or on the client. Among what I have read, the common answer is on the client. However, across the reading I’ve done (and videos I’ve watched) there are a few issues (see below). I’d appreciate some advice/guidance on how others have recently approached this problem while keeping optimization in mind.
Assumptions/Requirements with why I am ultimately trying to achieve:
- I’d like to handle playing and transitioning from one animation to within an NPC (not a player) that contains a Humanoid
- I plan to have at least 100 NPCs and preferably as many as possible without negatively impacting performance (server or client) in such a way to create lag for a player
- The NPCs will running with some level of AI where they will be independently moving (i.e. roaming) and there will be combat against players, which will create several points where animations will need to transition from idle, moving, fighting, skill use in combat, etc
- All players will need to visually see the animation (at least when the player is within a certain distance from the NPC)
Issues with the content I’ve come across during my research:
- Some articles are multiple years old and I’m unsure the content is still accurate/relevant considering there may have been changes to the Roblox platform
- Its often not clear whether suggestions in these articles are only appropriate to specific use cases and not appropriate to others.
2. It seems that at least for some articles the focus doesnt consider large NPC numbers or only considers minimal NPC activity such as static NPCs that only animate when a player interacts with them, which doesn’t address my goals. - Many offered solutions only provide a high level suggestion and dont provide any details on how to implement the solution or how that solution would work.
After spending considerable time researching this topic I’m left unsure of how to optimally approach managing playing animations client side or what people mean when they suggest running animations client side. Here are some of the concerns I have with the idea, but I am sure I am missing some critical pieces to make this work optimally.
The trigger for an animation to change/begin will be based on actions taken by an NPC (i.e. begin moving, stop moving and begin ideling, begin attacking, use skill, died, etc) or actions taken on an NPC (was hit). My thought is that when actions are taken will be functions executed to take that actions such as begin walking or to hit a target and within those functions that require an animation change a FireAllClients event could be fired. However, my concern with this is that is it optimal to fire an event to ALL clients every time any NPC begins an action and will this risk exhausting the event budget limits say when 100+ enemies need an animation to be started within a very short time period. However, I dont know how else to inform every client to play an animation client side.
With the focus on optimization, is the optimization argument, or the optimization gained, of handling animations client side > the network traffic of fire all clients for every animation change?
Otherwise, would having the server tell each NPC to play a loaded animation directly and have that replicate to each client, thus not requiring firing any events to clients, be more optimal?
Is there some other approach I am missing? Please let me know where I am going wrong and how to better approach this problem. Thanks
For reference, here are a few of the articles I’ve read: