Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Creating an RTS Game in Unity 2023

You're reading from   Creating an RTS Game in Unity 2023 A comprehensive guide to creating your own strategy game from scratch using C#

Arrow left icon
Product type Paperback
Published in Oct 2023
Publisher Packt
ISBN-13 9781804613245
Length 548 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Bruno Cicanci Bruno Cicanci
Author Profile Icon Bruno Cicanci
Bruno Cicanci
Arrow right icon
View More author details
Toc

Table of Contents (23) Chapters Close

Preface 1. Part 1: Foundations of RTS Games
2. Chapter 1: Introducing Real-Time Strategy Games FREE CHAPTER 3. Chapter 2: Setting Up Unity and the Dragoncraft Project 4. Chapter 3: Getting Started with Our Level Design 5. Chapter 4: Creating the User Interface and HUD 6. Part 2: The Combat Units
7. Chapter 5: Spawning an Army of Units 8. Chapter 6: Commanding an Army of Units 9. Chapter 7: Attacking and Defending Units 10. Chapter 8: Implementing the Pathfinder 11. Part 3: The Battlefield
12. Chapter 9: Adding Enemies 13. Chapter 10: Creating an AI to Attack the Player 14. Chapter 11: Adding Enemies to the Map 15. Part 4: The Gameplay
16. Chapter 12: Balancing the Game’s Difficulty 17. Chapter 13: Producing and Gathering Resources 18. Chapter 14: Crafting Buildings and Defense Towers 19. Chapter 15: Tracking Progression and Objectives 20. Chapter 16: Exporting and Expanding Your Game 21. Index 22. Other Books You May Enjoy

Spawning units using the Object Pooling pattern

The Object Pooling pattern was created to optimize memory usage and CPU performance by reusing objects that are pre-allocated in a pool, instead of instantiating a new object when needed and then destroying it. When the ObjectPool script is created, a fixed number of instances will be allocated and added to a list. Then, when an object is required, the Object Pool will give you an existing copy. When you do not need the object anymore, for example when a unit is destroyed by the enemy, the object is returned to the Object Pool.

We can use the Object Pooling pattern when we frequently need to create and destroy objects that are all the same or very similar. A good use case is bullets that are fired from a weapon; they are all the same and created and destroyed a lot. In this case, the Object Pooling pattern will reduce the overhead on the CPU to create and destroy an object as well as making it faster to reuse an object instead of instantiating...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime