Which is better: Multiple Standalone Scripts or one Main Script?

Let’s say you have tons of animals with navmeshagents. You want to move them around randomly and react with each other. Would it be better to have a main script loop over these animals and do the calculations or have multiple scripts on each animal?

This is purely hypothetical. If you need anymore information, I will be happy to clear up anything.
Also, I don’t really know what Tag I should put this as.

It’s quite standard to let each object manage itself. If you have situations where a manager is handling every animal then you get to a point where you have situations like this: What if one animal is trying to eat while another is trying to wander? All of a sudden you don’t just have a for loop that gives them a target, you have a sprawling series of if statements / a switch controlling the behaviour, and that’s not a fun process nor is it nice to debug.

Definitely have a standalone script for each animal for this.

2 Likes

If you’re dealing with a very large number of objects, there can be a performance benefit to having a single script instance (a manager) handle everything. That’s because there is a small amount of additional overhead for each individual instance of a script. Otherwise I agree with @Zalosath