Reader small image

You're reading from  Game Development Projects with Unreal Engine

Product typeBook
Published inNov 2020
Reading LevelBeginner
PublisherPackt
ISBN-139781800209220
Edition1st Edition
Languages
Tools
Right arrow
Authors (4):
Hammad Fozi
Hammad Fozi
author image
Hammad Fozi

Hammad Fozi comes from a gaming background and has been extensively working on Unreal Engine since 2017. He has been part of some very successful AAA projects such as Virtua FanCave (and Metaverse), Unnamed AAA Sci-Fi DJ Experience, Heroes and Generals, and Creed: Rise to Glory VR. Hammad has worked with teams who have had experience working at Ubisoft, Warner Bros. Games, 2K Games, and more! He has successfully helped teams consisting of 10–30 people to scale to 150+ in size over his very short yet impressive career. Hammad currently works as a senior C++ game developer and has extensive experience in working with VR and augmented reality, PC/PS5/Xbox/Android/iOS/macOS game development, and Web3/Metaverse/NFT systems (within Unreal Engine).
Read more about Hammad Fozi

Gonçalo Marques
Gonçalo Marques
author image
Gonçalo Marques

Gonçalo Marques has been an active gamer since the age of 6. He has been using Unreal Engine since 2016 and has done freelance and consulting work using the engine. Gonçalo also released a free and open source plugin called UI Navigation, which has garnered an extremely positive reception with over 100,000 downloads and is still receiving frequent updates and fixes. Thanks to the development of this plugin, he became an Epic MegaGrant recipient. He is now working at Funcom ZPX, a game studio in Lisbon that has contributed to games such as Conan Exiles, Mutant Year Zero, and Moons of Madness. Gonçalo is currently working on a new Funcom game in the Dune universe.
Read more about Gonçalo Marques

David Pereira
David Pereira
author image
David Pereira

David Pereira started making games in 1998 when he learned how to use Clickteam's The Games Factory. He graduated in computer science from FCT-UNL, where he learned about C++, OpenGL, and DirectX, which allowed him to create more complex games. After working in IT consulting for a few years, he joined Miniclip in Portugal where he worked on popular mobile games such as 8 Ball Pool, Gravity Guy 1 and Gravity Guy 2, Extreme Skater, iStunt2, Hambo, and many others. Since then, he has been the lead developer for MPC in the John Lewis Christmas VR Experience, worked on an earlier version of Mortal Shell, and did volunteer work teaching people with Asperger's how to make games with Unreal Engine 4. Today, he's working on his own game, a soon-to-be-announced first-person action RPG.
Read more about David Pereira

Devin Sherry
Devin Sherry
author image
Devin Sherry

Devin Sherry is originally from Levittown, NY, located on Long Island. He studied the topics of Game Development and Game Design at the University of Advancing Technology where he had earned his Bachelor of Arts in Game Design in 2012. During his time in college, Devin worked as a game and level designer with a group of students called Autonomous Games on a real-time strategy styled, third-person shooter called The Afflicted using Unreal Engine 3/UDK where it was presented at GDC in 2013 at the GDC Play Showcase. Today, Devin works as an independent game developer located in Tempe, Arizona, where he works on personal and contracted projects. His achievements include the title Radial Impact, which can be found in the Community Contributions section of the Learn Tab of Unreal Engine 4's Launcher, and his work on his YouTube Channel, Devin Level Design, where he educates viewers on game development within Unreal Engine 3, UDK, and Unreal Engine 4.
Read more about Devin Sherry

View More author details
Right arrow

14. Spawning the Player Projectile

Overview

In this chapter, you will learn about Anim Notifies and Anim States, which can be found inside Animation Montages. You will code your own Anim Notify using C++ and implement this notify in the Throw Animation Montage. Lastly, you will learn about Visual and Audio Effects, and how these effects are used in games.

By the end of this chapter, you will be able to play Animation Montages in both Blueprints and C++ and know how to spawn objects into the game world using C++ and the UWorld class. These elements of the game will be given audio and visual components as an added layer of polish, and your SuperSideScroller player character will be able to throw projectiles that destroy enemies.

Introduction

In the previous chapter, you made great progress with the enemy character's AI by creating a behavior tree that would allow the enemy to randomly select points from the BP_AIPoints actor you created. This gives the SuperSideScroller game more life as you can now have multiple enemies moving around your game world. Additionally, you learned the different tools available in Unreal Engine 4 that are used together to make artificial intelligence of various degrees of complexity. These tools included the Navigation Mesh, behavior trees, and Blackboards.

Now that you have enemies running around your level, you need to allow the player to defeat these enemies with the player projectile you started to create at the end of the previous chapter.

In this chapter, you will learn how to use the UAnimNotify class to spawn the player projectile at a specific frame of the Throw Animation Montage. You will also learn how to add this new notify to the Montage itself, and how...

Anim Notifies and Anim Notify States

When it comes to creating polished and complex animations, there needs to be a way for animators and programmers to add custom events within the animation that will allow for additional effects, layers, and functionality to occur. The solution in Unreal Engine 4 is to use Anim Notifies and Anim Notify States.

The main difference between Anim Notify and Anim Notify State is that Anim Notify State possesses three distinct events that Anim Notify does not. These events are Notify Begin, Notify End, and Notify Tick, all of which can be used in Blueprints or C++. When it comes to these events, Unreal Engine 4 secures the following behaviors:

  • Notify State will always start with Notify Begin Event.
  • Notify State will always finish with Notify End Event.
  • Notify Tick Event will always take place between the Notify Begin and Notify End events.

Anim Notify, however, is a much more simplified version that uses just a single function...

Playing Animation Montages

As you learned in Chapter 12, Animation Blending and Montages, these items are useful for allowing animators to combine individual animation sequences into one complete montage. By splitting the Montage into its own unique sections and adding notifies for particles and sound, animators and animation programmers can make complex sets of montages that handle all the different aspects of the animation.

But once the Animation Montage is ready, how do we play this Montage on a character? You are already familiar with the first method, which is via Blueprints.

Playing Animation Montages in Blueprints

In Blueprints, the Play Montage function is available for you to use, as shown in the following screenshot:

Figure 14.8: The Play Montage function in Blueprints

You have already used the function to play the AM_Throw Animation Montage. This function requires the Skeletal Mesh component that the Montage must be played on, and it requires...

Game World and Spawning Objects

When it comes to spawning objects into the game world, it is actually the World object that represents your level that handles the creation of said objects. You can think of the UWorld class object as the single, top-level object that represents your level.

The UWorld class can do many things, such as spawning and removing objects from the world, detect when levels are being changed or streamed in/out, and even perform line traces to assist with inter-object detection. For the sake of this chapter, we'll focus on spawning objects.

The UWorld class has multiple variations of the SpawnActor() function, depending on how you want to spawn the object, or by which parameters you have access to in the context in which you are spawning this object. The three consistent parameters to take into consideration are the following:

  • UClass: The UClass parameter is simply the class of the object that you want to spawn in.
  • FActorSpawnParameters...

Destroying Actors

So far in this chapter, we have put a lot of focus on spawning, or creating, actors inside the game world; the player character uses the UWorld class in order to spawn the projectile. Unreal Engine 4 and its base Actor class come with a default function that you can use to destroy, or remove, an actor from the game world:

bool AActor::Destroy( bool bNetForce, bool bShouldModifyLevel )

You can find the full implementation of this function in Visual Studio by finding the Actor.cpp source file in the /Source/Runtime/Engine/Actor.cpp directory. This function exists in all the classes that extend from the Actor class, and in the case of Unreal Engine 4, it exists in all classes that can be spawned, or placed, inside the game world. To be more explicit, both the EnemyBase and PlayerProjectile classes are children of the Actor class, and therefore, can be destroyed.

Looking further into the AActor::Destroy() function, you will find the following line:

...

Visual and Audio Effects

Visual Effects such as particle systems and sound effects such as Sound Cues play an important role in video games. They add a level of polish on top of systems, game mechanics, and even basic actions that make these elements more interesting or more pleasing to perform.

Let's start by understanding Visual Effects, followed by Audio Effects.

Visual Effects (VFX)

Visual Effects, in the context of Unreal Engine 4, are made up of what's called Particle Systems. Particle systems are made up of emitters, and emitters are comprised of modules. In these modules, you can control the appearance and behaviors of the emitter using materials, meshes, and mathematical modules. The end result can be anything from a fire torch, or snow falling, to rain, dust, and so on.

Note

You can learn more here: https://docs.unrealengine.com/en-US/Resources/Showcases/Effects/index.html.

Audio Effects (SFX)

Audio Effects, in the context of Unreal Engine 4...

Summary

In this chapter, you learned a lot about the importance of Visual and Audio Effects in the world of game development. Using a combination of C++ code and notifies, you were able to bring gameplay functionality to the player projectile and the enemy character colliding, as well as a layer of polish to this functionality by adding VFX and SFX. On top of this, you learned about how objects are spawned and destroyed in Unreal Engine 4.

Moreover, you learned about how Animation Montages are played, both from Blueprints and through C++. By migrating the logic of playing the Throw Animation Montage from Blueprint to C++, you learned how both methods work and how to use both implementations for your game.

By adding a new Animation Notify using C++, you were able to add this notify to the Throw Animation Montage, which allows the player to spawn the player projectile you created in the previous chapter. Through the use of the UWorld->SpawnActor() function, and adding a new...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Game Development Projects with Unreal Engine
Published in: Nov 2020Publisher: PacktISBN-13: 9781800209220
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.
undefined
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 $15.99/month. Cancel anytime

Authors (4)

author image
Hammad Fozi

Hammad Fozi comes from a gaming background and has been extensively working on Unreal Engine since 2017. He has been part of some very successful AAA projects such as Virtua FanCave (and Metaverse), Unnamed AAA Sci-Fi DJ Experience, Heroes and Generals, and Creed: Rise to Glory VR. Hammad has worked with teams who have had experience working at Ubisoft, Warner Bros. Games, 2K Games, and more! He has successfully helped teams consisting of 10–30 people to scale to 150+ in size over his very short yet impressive career. Hammad currently works as a senior C++ game developer and has extensive experience in working with VR and augmented reality, PC/PS5/Xbox/Android/iOS/macOS game development, and Web3/Metaverse/NFT systems (within Unreal Engine).
Read more about Hammad Fozi

author image
Gonçalo Marques

Gonçalo Marques has been an active gamer since the age of 6. He has been using Unreal Engine since 2016 and has done freelance and consulting work using the engine. Gonçalo also released a free and open source plugin called UI Navigation, which has garnered an extremely positive reception with over 100,000 downloads and is still receiving frequent updates and fixes. Thanks to the development of this plugin, he became an Epic MegaGrant recipient. He is now working at Funcom ZPX, a game studio in Lisbon that has contributed to games such as Conan Exiles, Mutant Year Zero, and Moons of Madness. Gonçalo is currently working on a new Funcom game in the Dune universe.
Read more about Gonçalo Marques

author image
David Pereira

David Pereira started making games in 1998 when he learned how to use Clickteam's The Games Factory. He graduated in computer science from FCT-UNL, where he learned about C++, OpenGL, and DirectX, which allowed him to create more complex games. After working in IT consulting for a few years, he joined Miniclip in Portugal where he worked on popular mobile games such as 8 Ball Pool, Gravity Guy 1 and Gravity Guy 2, Extreme Skater, iStunt2, Hambo, and many others. Since then, he has been the lead developer for MPC in the John Lewis Christmas VR Experience, worked on an earlier version of Mortal Shell, and did volunteer work teaching people with Asperger's how to make games with Unreal Engine 4. Today, he's working on his own game, a soon-to-be-announced first-person action RPG.
Read more about David Pereira

author image
Devin Sherry

Devin Sherry is originally from Levittown, NY, located on Long Island. He studied the topics of Game Development and Game Design at the University of Advancing Technology where he had earned his Bachelor of Arts in Game Design in 2012. During his time in college, Devin worked as a game and level designer with a group of students called Autonomous Games on a real-time strategy styled, third-person shooter called The Afflicted using Unreal Engine 3/UDK where it was presented at GDC in 2013 at the GDC Play Showcase. Today, Devin works as an independent game developer located in Tempe, Arizona, where he works on personal and contracted projects. His achievements include the title Radial Impact, which can be found in the Community Contributions section of the Learn Tab of Unreal Engine 4's Launcher, and his work on his YouTube Channel, Devin Level Design, where he educates viewers on game development within Unreal Engine 3, UDK, and Unreal Engine 4.
Read more about Devin Sherry