Search icon CANCEL
Subscription
0
Cart icon
Cart
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Unreal Engine 5 Game Development with C++ Scripting

You're reading from  Unreal Engine 5 Game Development with C++ Scripting

Product type Book
Published in Aug 2023
Publisher Packt
ISBN-13 9781804613931
Pages 384 pages
Edition 1st Edition
Languages
Author (1):
ZHENYU GEORGE LI ZHENYU GEORGE LI
Profile icon ZHENYU GEORGE LI
Toc

Table of Contents (18) Chapters close

Preface 1. Part 1 – Getting Started with Unreal C++ Scripting
2. Chapter 1: Creating Your First Unreal C++ Game 3. Chapter 2: Editing C++ Code in Visual Studio 4. Chapter 3: Learning C++ and Object-Oriented Programming 5. Chapter 4: Investigating the Shooter Game’s Generated Project and C++ Code 6. Part 2 – C++ Scripting for Unreal Engine
7. Chapter 5: Learning How to Use UE Gameplay Framework Base Classes 8. Chapter 6: Creating Game Actors 9. Chapter 7: Controlling Characters 10. Chapter 8: Handling Collisions 11. Chapter 9: Improving C++ Code Quality 12. Part 3: Making a Complete Multiplayer Game
13. Chapter 10: Making Pangaea a Network Multiplayer Game 14. Chapter 11: Controlling the Game Flow 15. Chapter 12: Polishing and Packaging the Game 16. Index 17. Other Books You May Enjoy

Checking an Actor instance’s actual class type

In Unreal, the OOP approach regularly utilizes inheritance to declare class relations. Even though inheritance has the advantage of code reuse, it has the limitation of storing and returning instances while only knowing the base class types.

Based on the inheritance design pattern, type casting very often occurs in OOP. An example in Unreal scripting is that when a collision triggers an overlap event, the two parameters of the event function are both AActor* type pointers, whereas they should be of the APlayerAvatar*, AEnemy*, or ADefenseTower* type.

To find out whether AActor* is another child class type pointer, we use the Cast function to cast the AActor* pointer to the required type of pointer (APangaeaCharacter*, for example) and check whether the result is nullptr or not. If the Cast operation fails, it means that the actor is not the type of actor we need:

void AWeapon::OnWeaponBeginOverlap(AActor* OverlappedActor...
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 €14.99/month. Cancel anytime