Proxy vs Factory

I’ve read and reread the intros to Collection Factories and Collection Proxies about half a bajillion times now, and while I think I understand the basics of using them, I still don’t have a whole lot of clarity on when to use which, and keep flip-flopping back and forth over which is ideal. The collection proxy intro says they have different use cases, but it doesn’t really go into any detail over what some different use cases might be.

So I’ve got my own, real life use cases.

One description that might apply to my game might be “Daily Planner: The Game”. It is fairly GUI-dependent, with a bunch of different screens for viewing and interacting with various pieces of data. My primary game screen has a split screen for 3 different characters, each of which can be selected from a plethora of unlockable characters. I am currently loading the overall selection screen via a Factory, because I am using Monarch, which tells me to use Factories for top-level screens. Fair enough.

But for the split screens, the main reason I am using Screen Factories to generate each sub screen is because I used Screen Factories to make the top level screen; and, unsure which pattern is preferable in this case, I went with what I already know. And as for populating the sprites, tilesets, and assorted other data that come with each prefab character selection? Well, Factories again. No idea if that’s optimal or not.

Now I’m adding my second screen: when you click on one of the characters in the split screen, I want to bring up the Character Detail screen for that character. Aside from the question of whether I should have one instance of the Detail screen or three (different characters will actually have different formats for the Detail screen, if that matters), reflex says: Factories again!

But, um. These Collection Proxy thingies. I’m sure they’re good for something, right? Am I perhaps using Factories for some objects that I would be better served by Proxies? Or have I just, by completely random luck of the draw, managed to come up with a set of circumstances that are all best served by Collection Factories?

2 Likes

Collection factories spawn resources that are already loaded into memory.

Collection proxies load resources into memory before you can use them.
This is more important when you want to load e.g. different levels of a game, where the memory of each level might be large.
Also, another small benefit is that you can set the update time on collection proxies (i.e. pause them)

3 Likes

Use a factory to spawn one or more instances of a hierarchy of game objects. This could be a player character, space ship, a boss monster or anything else which require more than one game object.

Use a proxy to load a single instance of a hierarchy of game objects. The typical use case is to load and unload levels, scenes, screens or anything else that is a bit bigger and has it’s own set of resources that you don’t want to have in memory all the time

Side-note: You can also control when the resources of a factory are loaded into memory through the Load Dynamically checkbox.

2 Likes