Adding a bunch of listeners, along with all kinds of other scripts, my character is already at 30~ components. While it is usable now, looking for components in the inspector have become a bit of a hassle as there appears to be no filter and I expect it to grow much more.
How do you personally manage it? Do you just create additional game objects for the game object to organize it better? Or perhaps you try and group scripts better? How many components is too much for one game object?
I’m not aware of what the actual upper limit is for components on a GameObject. You can collapse components in the inspector so they take up little space. I do that frequently for objects with lots of components.
Do you really need all these components though? If you have a series of rather small scripts, you would probably be better off with combining many of them. I have separate scripts for entirely separate and significant functionality. But if you have just a few methods in each script you should just probably combine them.
When I have a rather trivial amount of code that isn’t really a part of any other major functionality, I put it in a catch all script on that object, which ends up growing in size to the other major scripts but just has a bunch of minor features all together but separated with #region tags.
Yeah it is not my first choice. But as an example, I’ve got an important prefab which represents the ship that the players sail around with about 15 decently large scripts attached. I had a bunch of small features though that if each had their own scripts would have bumped it up to over 30 scripts. Turning on/off a water wake when going certain speeds, turning on/off torches at certain times of day, things like that, all one or two methods each. I ended up just creating a MiscShipActions.cs script and put them all in there.
Saved my sanity a lot, since I am constantly making improvements to scripts on this prefab as my game develops, but rarely make changes to these simple small methods. So it keeps them out of the way in my inspector, and doesn’t clutter up my scripts folders or any more important scripts I often edit.
Ah the old Misc.cs hehe don’t we all have them though I actually think we only have a misc file for editor misc stuff in our game nifty stuff like checking ligjtmap scales on objects, checking indirect intensity on all lights etc
Do they have to be components? Although it kind of comes down to semantics, if you could shift some components to be pure class objects instead you could make a single component that exposes parameters and excuses monobehaviour functionality.
I guess it’s still a bit of a ‘God’ object but at least you have some level of code partitioning and super ability of the classes.