I’m making a jrpg style game, similar to the early Legend of Zelda games and was looking for some advice. The map is currently set up like a grid with 16 “rooms”, each room containing about 5 enemies that wander between 5 waypoints in their respective room. All the rooms are an box collider blocking the exits so they are confined to their room. All the enemies are constantly active and wandering, running the same three scripts that handle their Health, Movement, and Attack. I am planning on expanding the map so I wanted to know if I’m approaching it the correct way before I get to far into it. Is it okay to have 50-100 or even up to 500 enemy gameobjects active or should I make them spawn and despawn when I cross a room border? Also, they all have rigidbody, capsule collider, nav mesh agent, and animator componants attached to them. As a sidenote, I constantly see tutorials and such on how to do stuff in Unity, but have yet to find a decent guide to planning/mapping out a game, if anyone has seen something like that, I’d be interested in reading it. Thanks for any advice.
It all depends on so many questions that it is hard to tell you exactly when you have reached “the limit”, but I would warn about early optimization. If you are going to mobile this could certainly be an issue, but before those scripts become a performance issue it is much more likely that the mobile GPUs would choke from the rendering without proper batching regardless. If you are on PC you might get away with it, but you might not… Depending on what your target specs are a slew of other issues could also be the real bottleneck, not your enemies.
In my opinion, what you are currently doing with your enemies is probably not going to kill performance on any decent hardware, but that definitely depends on your target platform. Having them spawned and enabling them on, or even running a very limited amount of the AI while the player is far away (depending on your game you could try actually enabling these components based off distance, what rooms are near others, etc) is probably better than instantiating these objects (as instantiation is very slow on some platforms). Once again though, there is almost never a ‘one-size fits all’ solution and depending on other factors your game might run perfectly fine instantiating all of your enemies.
In short, I would continue on developing your game and getting it to a point to where you can really ask yourself “is this fun and worth all the extra work it might take to get it to a point of actually releasing this for other people to play?”. If that answer is yes, then profile your game with the Unity profiler, and ensure to do it on the target platforms. At that point you will be able to identify the real bottlenecks of your almost finished game, and be able to maximize your development time on things that make your game more fun.
Answer little bit depends on how heavy your enemy objects are and what is target platform. However generally you can’t have 500 active AI running around without killing performance and you have to activate/deactivate them depending on distance.
In most games where there are large amount of moving objects they are grouped because pathfinding is generally pretty heavy process.