top of page

Assignment 10

- Object Pooler -

AND

- Singleton -

The objective of this assignment was to create a mini-game with Unity and C# that uses an implementation of the object pooler design pattern and singleton design pattern.

Play the Game

UML Diagram

- Interactable Object Spawning -

Utilizing The Singleton and Object Pooler Patterns

Object Pool and Singleton UML.jpg

Questions and Answers

1.    What GameObjects are you spawning with the Object Pool Design Pattern?

I’m spawning in a variety of shapes with the object pool design pattern. Each shape has its own pool, and on spawn a unique behavior is added to that shape using the Strategy Pattern!

2.    When is your Object Pool filled with inactive GameObjects?  On Start() when the scene loads or does something trigger the pool to be filled?  If something triggers it, what triggers the pool to be filled with inactive GameObjects?

The Object Pool is filled with inactive GameObjects when the scene loads.

3.    In your mini-game, what makes the GameObjects be set active and spawn into your scene from the Object Pool?  Does the player do something, or is it a repeating coroutine, or something else?

The GameObjects are set active and spawned in at random times by the ShapeSpawner game object via a repeating coroutine. This coroutine starts when the player presses START after reading the instructions.

4.    What makes the GameObjects return to the Object Pool in your mini-game?  In the example code, the objects were recycled by adding them to the back of the Object Pool queue when they were spawned.  Are you recycling them like that, or adding them back to the queue when something happens in your game?  (Either is okay.)  If you are adding them back to the queue when something happens, what happens if the pool is empty and the game tries to spawn a GameObject from the pool?  Does it spawn an object or not? (Either is okay.)

The GameObjects are recycled after they are spawned in, similar to the example code. There is also an out of bounds trigger that deactivates the game object when it collides with it. I did this just so rigidbodies wouldn’t be active in the game when they’re not being used and not on the screen.

5.    What were the benefits of using the Object Pool Pattern to make your mini-game?

Although my game is small enough to not take performance into huge consideration, I could see how the object pool pattern would help a lot in terms of increasing performance, especially with particle effects or a game with massive amounts of incoming enemies. It was also nice that I incorporated an IPooledObject interface, so if an IPooledObject was spawned in by the ObjectPooler, I could call the OnSpawn() method to make the game object perform some behavior right when it was spawned in. Again, my game was small enough to where I didn’t necessarily need to use this pattern, but using it was fun and provided me a lot of ideas as to when I might want to use it.

6.    Did you find any drawbacks to using the Object Pool Pattern?  If so, what were they?

I had some trouble figuring out how to use the Pool system initially. I was wondering if I could use multiple prefabs with a single Pool, and that would surely be possible with some modifications to the code, but overall I see how a single pool should be responsible for a single object. In the end, I had separate pools for each shape.

7.    What were the benefits of using the Singleton Pattern to make your mini-game?

The singleton pattern allowed me to easily call methods on manager classes and the object pooler class. Many times, I’ve found it beneficial to use the Singleton especially if the concrete class is required to extend MonoBehaviour. With a static class, this would not be possible.

8.    Did you find any drawbacks to using the Singleton Pattern?  If so, what were they?

Throughout this semester, I’ve been really trying to keep my code decoupled, and after learning more about the singleton pattern I can see how it creates a tight coupling between classes, but if used sparingly I can see its benefits. I also tried to incorporate a lazy initialization method, but I had some trouble getting that working. My main problem was that I couldn’t use the this keyword in a static method or a static property. I plan on returning to this at a later time to get it working so I can use it in the future though.

9.    What is the player’s goal in your mini-game and what makes it challenging?

Inspired by Fruit Ninja, my mini-game requires players to click on the incoming shapes, avoiding the black and red ones since they’ll decrease the player’s score. It’s challenging because the shapes pop up randomly and on occasion in groups. Additionally, if the player misses a shape that will grant them a score increase, they’ll get a score decrease! Overall, I tried to make the black shapes represent bombs in Fruit Ninja and everything else like a fruit.

10.    How does the game communicate its goal(s) to the player?

The goal is communicated through the on-screen instructions at the start of the game. The win condition and lose condition are also displayed here.

11.    How can the player fail at the game and how does the game detect it?

The player can fail at the game if their score drops below or hits -5. Once this occurs, GAME OVER will be displayed on the screen. Once the game ends, after 3 seconds the game will reload.

12.    How does the game give players feedback about how well they are doing?

The score is displayed in the top left corner of the screen. Once the player left clicks on an object, it will disappear and their score will increase or decrease.

Kyle Grenier

Immersive Technology and Game Developer

app-icon.png
GitHub-Mark-Light-64px.png
LinkedIn_icon_circle.png
bottom of page