Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Hands-On Unity  Game Development - Fourth Edition

You're reading from  Hands-On Unity Game Development - Fourth Edition

Product type Book
Published in Jan 2024
Publisher Packt
ISBN-13 9781835085714
Pages 742 pages
Edition 4th Edition
Languages
Authors (2):
Nicolas Alejandro Borromeo Nicolas Alejandro Borromeo
Profile icon Nicolas Alejandro Borromeo
Juan Gabriel Gomila Salas Juan Gabriel Gomila Salas
Profile icon Juan Gabriel Gomila Salas
View More author details

Table of Contents (28) Chapters

Preface 1. Section 1: Getting Started with Unity
2. Embark on Your Unity Journey 3. Crafting Scenes and Game Elements 4. From Blueprint to Reality: Building with Terrain and ProBuilder 5. Seamless Integration: Importing and Integrating Assets 6. Section 2: Mastering Programming and Gameplay Mechanics
7. Unleashing the Power of C# and Visual Scripting 8. Dynamic Motion: Implementing Movement and Spawning 9. Collisions and Health: Detecting Collisions Accurately 10. Victory or Defeat: Win and Lose Conditions 11. Starting Your AI Journey: Building Intelligent Enemies for Your Game 12. Section 3: Elevating Visuals, Effects, and Audio
13. Material Alchemy: Using URP and Shader Graph for Stunning Visuals 14. Captivating Visual Effects: Harnessing Particle Systems and Visual Effect Graph 15. Enlightening Worlds: Illuminating Scenes with the Universal Render Pipeline 16. Immersive Realism: Achieving Fullscreen Effects with Post-Processing 17. Harmonious Soundscapes: Integrating Audio and Music 18. Section 4: Designing User Interfaces, Animations and Advanced Concepts
19. Interface Brilliance: Designing User-Friendly UI 20. Next-Gen UI: Creating Dynamic Interfaces with UI Toolkit 21. Animated Realities: Creating Animations with Animator, Cinemachine, and Timeline 22. Performance Wizardry: Optimizing Your Game with Profiler Tools 23. From Prototype to Executable: Generating and Debugging Your Game 24. AR/VR 25. Massive Worlds: Introduction to DOTS 26. Other Books You May Enjoy
27. Index

Massive Worlds: Introduction to DOTS

While Unity is a powerful and performant engine (when used properly), there’s a limit on how many GameObjects you can have without reaching performance limits. While the Object-Oriented Programming (OOP) paradigm provides a convenient way to code a game, due to its internal works, it won’t always take advantage of all the modern CPU features, like caching, Single Instruction Multiple Data (SIMD) operations, and multi-threading. While it isn’t impossible to use such features in OOP, doing so is not a trivial task and can lead to difficult-to-track bugs. Unity’s response to that issue was releasing the first production-ready version of the DOTS packages, which will help us with these problems.

In this chapter, we will examine the following build concepts:

  • Understanding what DOTS is
  • Creating our first DOTS game
  • Creating gameplay in DOTS

Let’s start by getting an idea of what DOTS...

Understanding what DOTS is

The Unity Data-Oriented Technology Stack (DOTS) is a set of Unity packages that allows us to write data-oriented code easily. While there are plenty of packages in the DOTS stack, let’s focus on the three key ones that serve as pillars for the rest:

  • Entities: Unity takes on the ECS pattern. It replaces GameObjects and MonoBehaviours with Entities, Components, and Systems (ECS, a paradigm in Unity that separates data (components) from logic (systems), enhancing performance and scalability), a cache-friendly way to store and update our scene objects. It provides considerable performance boosts, especially in games with lots of objects.
  • Jobs: The Unity way to create multi-threaded code. It groups data and code that processes jobs. They are executed in parallel thanks to the job scheduler, which guarantees that explicit dependencies between jobs are respected. This avoids classic multi-threading issues like deadlocks and race conditions...

Creating our first DOTS game

There is plenty to learn in order to create performant games with DOTS, so let’s start by creating a simple project featuring cubes moving forward. Emphasis on cubes – we are going to have thousands of them! I know it is not the most exciting project, but bear with me, as in the Creating Gameplay in the DOTS section in this chapter, we will convert it into an actual (but simple) game.

In this section, we will examine the following DOTS concepts:

  • Creating a DOTS project
  • Creating entities with subscenes
  • Creating components and bakers
  • Creating systems using Jobs and Burst
  • Debugging systems jobs and queries

Let’s start by discussing how to set up a project to be compatible with DOTS.

Creating a DOTS project

The first step for creating a DOTS project is the one you should already know by this point in the book: creating a brand-new URP project. If you are not sure how to do it, please...

Creating gameplay in DOTS

Lots of things we do in MonoBehaviours, like instantiating objects or getting other object data (for example, their position), are quite differently implemented in DOTS. In this section, we will examine how to achieve these things in DOTS:

  • Moving using input and tag components
  • Creating seeking missiles using component lookups
  • Destroying the character with entity command buffers
  • Dealing with errors in bursted code
  • Instantiating missiles with entity Prefabs
  • Making the camera follow our character
  • Exploring other DOTS features

Let’s start by discussing how to modify our movement code to respond to input.

Moving using input and tag components

Let’s start creating gameplay by using input to move the cube. We need to change our movement job to provide it with the input values. We will do this the same way as we provided delta time by passing the input values to the job. In the next image...

Summary

In this chapter, we learned how to start using DOTS by creating our own components and systems to add gameplay to a simple game. We saw how to use input, and the DOTS transform API to move and rotate objects, and we also saw how to spawn and destroy objects.

DOTS is a new engine on its own, running inside Unity. The way it works is vastly different, and except for a few systems like the rendering pipelines, almost all DOTS features work very differently from their GameObject counterparts. Also, DOTS is still quite new, meaning it still has missing features and could be subjected to substantial changes in the next versions.

This makes it a possible risk for creating new projects, but on the other hand, the performance it can achieve could be decisive for big and ambitious projects. It is an interesting piece of technology that can revolutionize game development, and every day, it is getting more powerful and stable. It’s a good time to start learning about it...

lock icon The rest of the chapter is locked
You have been reading a chapter from
Hands-On Unity Game Development - Fourth Edition
Published in: Jan 2024 Publisher: Packt ISBN-13: 9781835085714
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 AU $19.99/month. Cancel anytime}