I understand it’s an optimization, that each factory acts as a pool of objects of its kind. But if the game starts growing and its content along with it, factory numbers start growing alarmlingly.
This is the state of our current game:
And it doesn’t look like much, but that’s because we are doing some nasty things to keep factory numbers low. For instance, the interactable_factory creates interactables, which are devices the user can interact with, and look like this:
It contains, among other scripts, the interactable script, which sends a message to its own go with the interactable data in its init function. Interactables can be goal_devices, spawners and vending_machines. Now, each script receives that message and if the interactable is not of its kind, it disables itself. It’s the interactable_factory which tells each interactable what it is (levels are created procedurally!) So a goal_device checks data and if it’s a goal device it works, otherwise deactivates itself and ignores all future messages.
May be ugly, but it allows us to keep things under a single game object. The alternative is a different .go - even when it basically does the same thing with little differences - and a specific factory for each one. Ouch.
Same for projectiles, we have a single projectile.script file that handles different kinds of projectiles, and a single projectile.go that configures itself with the correct atlas, sprite animation and such. Instead of a factory for each kind of projectile, it’s again centraliced in a single projectile_factory.script and a single projectile.go. In other game engines we would probably use different components, plugging them in on the fly to achieve different behaviours. Here we initialize the script this way:
It works because they basically use the same collider. Otherwise… PHEW. We would need a different go for each one or we have to do something like we did with factories: different collider shapes that we deactivate when not needed, or something like that.
I guess it depends a lot on the game you are making, and this solution currently suits us and our project, but I would love to know how you organice yours when things grow! Do you really have one single .go file for each thing, no matter how alike they are, and its own factory?