Reader small image

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

Product typeBook
Published inAug 2023
Reading LevelBeginner
PublisherPackt
ISBN-139781804613931
Edition1st Edition
Languages
Tools
Right arrow
Author (1)
ZHENYU GEORGE LI
ZHENYU GEORGE LI
author image
ZHENYU GEORGE LI

Zhenyu George Li is a passionate video game developer with 20+ years of experience. He has contributed significantly to many games and serves as a senior development consultant at Unity. His early immersion in technologies like C/C++, DirectX, OpenGL, and Windows GUI laid the foundation for his success. Notable titles in his portfolio include Magic Arena, Halo Infinity, Stela, Dead Rising 2, and The Bigs 2. He has gained extensive knowledge in programming, graphics, animation, gameplay, AI, multiplayer, and UI using Unreal and Unity engines. Additionally, he has taught UE at Vancouver Film School and has college teaching experience at College of Interactive Arts and Hefei Union University.
Read more about ZHENYU GEORGE LI

Right arrow

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 page is locked
Previous PageNext Page
You have been reading a chapter from
Unreal Engine 5 Game Development with C++ Scripting
Published in: Aug 2023Publisher: PacktISBN-13: 9781804613931

Author (1)

author image
ZHENYU GEORGE LI

Zhenyu George Li is a passionate video game developer with 20+ years of experience. He has contributed significantly to many games and serves as a senior development consultant at Unity. His early immersion in technologies like C/C++, DirectX, OpenGL, and Windows GUI laid the foundation for his success. Notable titles in his portfolio include Magic Arena, Halo Infinity, Stela, Dead Rising 2, and The Bigs 2. He has gained extensive knowledge in programming, graphics, animation, gameplay, AI, multiplayer, and UI using Unreal and Unity engines. Additionally, he has taught UE at Vancouver Film School and has college teaching experience at College of Interactive Arts and Hefei Union University.
Read more about ZHENYU GEORGE LI