Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Procedural Content Generation for Unity Game Development
Procedural Content Generation for Unity Game Development

Procedural Content Generation for Unity Game Development: Harness the power of procedural content generation to design unique games with Unity

eBook
AU$41.99 AU$60.99
Paperback
AU$75.99
Subscription
Free Trial
Renews at AU$24.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $24.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

Procedural Content Generation for Unity Game Development

Chapter 1. Pseudo Random Numbers

This chapter will introduce the idea of procedural content generation and one highly useful component, pseudo random numbers. Later in the chapter, you will use pseudo random numbers to create a derivation of the classic Hello World program. For convenience, procedural content generation will be abbreviated to PCG for the remainder of the text. Let's also abbreviate pseudo random numbers to PRNs.

Here's a quick overview of what the chapter will cover and what you will learn:

  • Define PCG: What it is and what you can do with it
  • Discover PRN generation
  • Learn how PRNs relate to PCG
  • Use PRNs in our first program
  • Develop a new randomized PCG like the Hello World program

In this chapter, we will complete a very simple step-by-step example. The example in this chapter will be simple enough to help introduce newcomers to Unity and also serve as a refresher to those coming back after some time away. However, it is important to remember that the successive examples will be much more involved. It is best that you are fundamentally familiar with Unity and C# scripting in Unity.

Note

Unity Technologies offers a range of tutorials for beginners at https://unity3d.com/learn/tutorials.

You can also reference the Unity Documentation if you need to know the usage of any specific part of Unity at http://docs.unity3d.com/Manual/index.html.

Now, let's dive in and start learning.

Introducing PCG

We begin our learning adventure with the broad concept of PCG. The key word here is procedural. A procedure in programming, simply put, is an instruction to be executed. Procedures are the main paradigm in computer programming. A script you write in Unity is just a set of instructions or procedures we want Unity to perform.

You use procedures, methods, or functions as a means to communicate the instructions you want the computer to complete. We can use these same procedures to instruct the computer to generate content in many different ways. We can apply this idea to a broad range of programming disciplines such as data visualization, dynamic advertising, and so on, but in this book, we are using it for video games.

If procedural is the how then content is the what. Content can be anything we are presenting to the user. In our Hello World example later in the chapter, our content will simply be text. However, video games have a wide range of assets that make up the content we want to deliver to a player.

Typically, we think of the levels, character models, and other art assets when we think of content in video games. But there is also textures, music, sounds, story, artificial intelligence, and more that together make up the content of a game. PCG is the concept or paradigm by which all these pieces of content can be generated with some well-written code. PCG can be applied to nearly all aspects of a game through scripting, and you will learn some of the main ways to do this throughout the book.

Introducing PCG

On the left is a hand-drawn texture, and on the right is a Procedurally Generated texture

What's exciting about PCG is that we can let the computer take some of the responsibilities of the designer by giving it some instructions and letting it create parts of the game world on its own. We might even be surprised by the results. As developers, we usually do not like being surprised by our script's actions, but in this case, it's part of the plan.

PCG can also come in a few different forms for practical use. We can generate content from scratch, such as the texture see earlier, or we can generate assets from a set of premade parts, such as generating a tavern scene from premade props such as tables, chairs, barrels, and crates. Another option, though, is providing tools to the player to take on the role of creating content. The player creating content isn't necessarily PCG but you will have created a PCG system that now takes user input as a parameter. A great example of this is the popular game Minecraft developed by Mojang.

Introducing PCG

A player-created building in the popular game Minecraft

Minecraft is also an example of one of the most popular uses of PCG, randomization. Players in Minecraft can make structures and break down the land around them. However, the game's entire landscape is based on randomization. Randomization is used in many games, both virtual and table top. Randomness introduces a chance factor that creates fun out of unpredictability.

However, the most important thing about randomness in video games is that it is almost impossible to achieve true randomness on a computer system. This is why we refer to them as pseudo random numbers, because they are technically not random. We will explore this aspect of randomness, or pseudo randomness, later in the chapter with PRNs.

Usage of PCG

The reasons we might consider using PCG include unique, robustness, adaptability, and size. We might strive for our player to experience the game in their own truly unique play-through. We could use PCG to take the content that we have designed and make truly robust games that would take many hours to explore every inch of. We can make our game adapt to the player in interesting ways such as scaling the difficulty to easier or harder based on the actions of the player.

Size, though, is an interesting benefit to PCG. Well before games played with amazing HD graphics at 60 frames a second, they were mostly text based. Early computer systems were very limited both in processing power and storage memory. One of the earliest occurrences of PCG was in games that procedurally generated levels using ASCII characters. We can see an example of this in the game Rogue developed in the 1980s. We discuss Rogue and the subsequent sub-genre of games Roguelike in later chapters.

PCG was thus a solution, of sorts, to the fact that early computers really had no means to present graphics to the player. Graphics comprise the bulk of a game in terms of size taking a lot of processing power and memory. The procedurally generated ASCII levels of Rogue were calculated instead of being loaded from the file. This meant early computer systems could use memory and processing power as needed instead of needing a lot of memory all at once when you start a predefined game level.

We can also consider size savings in terms of our team as well. A designer/artist typically will need to make every piece of game content by hand. As games get larger, it becomes more difficult to create enough unique content within one game. Games lose their reward factor and players become bored easily when they see continuous repetition of in-game content. We then need to produce more content, which means more designers, artists, and individual assets. PCG helps alleviate this need by taking on some of the burden of producing unique content.

PCG can thus be viewed as a tool for the designer. There is a very creative facet to the idea of PCG. We can design pieces or modules of a whole, like a level or item, and use PCG to put them together in unique and interesting ways. We could also make 3D models, but then, we would have to generate the textures for them. Otherwise, we could generate full levels from scratch and add in some designed props. There are plenty of possibilities to fit the situation or team's needs.

Usage of PCG

Some of Gearbox Software's Borderlands procedurally generated weapons, each generated from asset modules

You also have a unique opportunity to create games that can expand infinitely (or close to it). We will see this later in the book when we learn how PCG can be used to create a game level that never ends. Are you convinced that PCG is an amazing game development component?

Left arrow icon Right arrow icon

Key benefits

  • Learn the basics of PCG development
  • Develop a 2D game from start to finish
  • Explore all the different ways PCG can be applied in games

Description

Procedural Content Generation is a process by which game content is developed using computer algorithms, rather than through the manual efforts of game developers. This book teaches readers how to develop algorithms for procedural generation that they can use in their own games. These concepts are put into practice using C# and Unity is used as the game development engine. This book provides the fundamentals of learning and continued learning using PCG. You'll discover the theory of PCG and the mighty Pseudo Random Number Generator. Random numbers such as die rolls and card drafting provide the chance factor that makes games fun and supplies spontaneity. This book also takes you through the full development of a 2D game. Starting with level generation, you'll learn how PCG can make the game environment for you. You'll move into item generation and learn the different techniques to procedurally create game items. Thereafter, you'll be guided through the more abstract PCG areas such as scaling difficulty to the player and even generating music! The book helps you set up systems within your games where algorithms create computationally generated levels, art assets, quests, stories, characters, and weapons; these can substantially reduce the burden of manually creating every aspect of the game. Finally, you'll get to try out your new PCG skills on 3D terrain generation.

Who is this book for?

This book is for Unity game developers, especially those who work on indie games. You should be familiar with Unity and C# scripting but you'll be able to jump in and start learning PCG straightaway.

What you will learn

  • Understand the theory of Procedural Content Generation
  • Learn the uses of Pseudo Random Numbers
  • Create reusable algorithm designs for PCG
  • Evaluate the data structures for PCG
  • Develop smaller games with larger amounts of content
  • Generate content instead of spending time designing every minute detail
  • Learn when and how to add PCG to your game
  • Learn the fundamental techniques of PCG

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jan 30, 2016
Length: 260 pages
Edition : 1st
Language : English
ISBN-13 : 9781785287473
Vendor :
Unity Technologies
Languages :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $24.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Jan 30, 2016
Length: 260 pages
Edition : 1st
Language : English
ISBN-13 : 9781785287473
Vendor :
Unity Technologies
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
AU$24.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
AU$249.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just AU$5 each
Feature tick icon Exclusive print discounts
AU$349.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just AU$5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total AU$ 219.97
Unity UI Cookbook
AU$75.99
Unity 5  Game Optimization
AU$67.99
Procedural Content Generation for Unity Game Development
AU$75.99
Total AU$ 219.97 Stars icon

Table of Contents

11 Chapters
1. Pseudo Random Numbers Chevron down icon Chevron up icon
2. Roguelike Games Chevron down icon Chevron up icon
3. Generating an Endless World Chevron down icon Chevron up icon
4. Generating Random Dungeons Chevron down icon Chevron up icon
5. Randomized Items Chevron down icon Chevron up icon
6. Generating Modular Weapons Chevron down icon Chevron up icon
7. Adaptive Difficulty Chevron down icon Chevron up icon
8. Generating Music Chevron down icon Chevron up icon
9. Generating a 3D Planet Chevron down icon Chevron up icon
10. Generating the Future Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
(2 Ratings)
5 star 0%
4 star 0%
3 star 100%
2 star 0%
1 star 0%
Jesse May 29, 2016
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
[Some comments in this review may be outdated. The review was originally posted on 2016-05-29.]I bought this book hoping to see some interesting PCG techniques and in-depth insights, but was mostly disappointed. The book is suitable only as a basic introduction to PCG with Unity. People who have any prior experience with PCG will generally find little of value in this book.The quality of the writing is mediocre overall. There's generally no trouble with basic comprehension of what the author is saying, but the book has numerous minor typos and sometimes poor grammar/semantics. The style of the sentences is simple to the point of feeling stilted and bland. There's a fair number of sentences that don't really mean much beyond what the reader would already be assuming anyway. Some of the code examples contain typos of variable names, which is thus proof that at least some of the code samples were never tested at all (otherwise the compiler would have caught the typos).The author makes some incorrect statements about PCG in the book. For example, on the top of page 7 he says rolling dice and simulating other kinds of physical systems would allow you to generate truly random numbers on a computer, but because doing so is computationally expensive programmers use pseudo-random numbers instead. This statement is completely false. That is not the reasoning behind pseudo random number use. A dice simulation or other physics simulation would also be just as pseudo random. The author basically just completely fabricated this statement instead of doing proper research. There are several other examples in the text of him basically doing the same thing.I get the feeling that the author himself didn't actually know much of anything about PCG prior to writing the book. That being said, it would probably be a fair into to a beginner, provided the beginner is aware that the author's work contains errors and some bad advice from time to time. The code quality is generally poor to mediocre. The author frequently mixes implementation details that have no business being put together. Several of the classes he uses are also probably superficial and could be refactored (especially the "Manager" classes). The book has either been poorly edited or was never edited at all. The authors code is not very well factored and not very modular. His advice to use inheritance on a few occasions is also misguided. Components are a superior solution when properly understood.I have read online that Packt Publishing has a reputation for "quantity over quality" publishing. I even read about a different author on a forum describing how when he submitted their book to them, the publishers actually *added* more errors into the book through their editing than they removed from it and actually made the English quality worse instead of better. Supposedly they have non-technical editors who make changes to the technical text without actually fully understanding the context and semantics. Thus, it is possible some of the mediocre writing is the publishers fault and not the author's, but this is all speculation.The PCG techniques the author chooses to use are some of the most crude and uninteresting forms of it. He basically always just uses a plain old random number to select from a set of options every iteration. You won't find any advanced PCG algorithms in this book.In summary: This book is OK if you are a beginner at PCG, provided you understand that the author's work contains some misinformation and bad programming practices. If instead you are looking for deep insights into PCG or interesting PCG techniques (like me), then you should definitely avoid this book. It has little value to anyone who already understands the basics of PCG.You should also be wary of this publisher.
Amazon Verified review Amazon
Amazon Customer Apr 05, 2016
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
Bought this book expecting to learn basics of PCG. And I wasn't disappointed. This book definitely has lots of information about content generation but is also has errors. Too many of them for the book of this size and price.For example, not all code examples in the book are working as some parts of code are missing or are being used not in the right place.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.