Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Game Development Projects with Unreal Engine

You're reading from  Game Development Projects with Unreal Engine

Product type Book
Published in Nov 2020
Publisher Packt
ISBN-13 9781800209220
Pages 822 pages
Edition 1st Edition
Languages
Authors (4):
Hammad Fozi Hammad Fozi
Profile icon Hammad Fozi
Gonçalo Marques Gonçalo Marques
Profile icon Gonçalo Marques
David Pereira David Pereira
Profile icon David Pereira
Devin Sherry Devin Sherry
Profile icon Devin Sherry
View More author details

Table of Contents (19) Chapters

Preface
1. Unreal Engine Introduction 2. Working with Unreal Engine 3. Character Class Components and Blueprint Setup 4. Player Input 5. Line Traces 6. Collision Objects 7. UE4 Utilities 8. User Interfaces 9. Audio-Visual Elements 10. Creating a SuperSideScroller Game 11. Blend Spaces 1D, Key Bindings, and State Machines 12. Animation Blending and Montages 13. Enemy Artificial Intelligence 14. Spawning the Player Projectile 15. Collectibles, Power-Ups, and Pickups 16. Multiplayer Basics 17. Remote Procedure Calls 18. Gameplay Framework Classes in Multiplayer

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 2020 Publisher: Packt ISBN-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.
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 €14.99/month. Cancel anytime}