Book Image

Learning C++ by creating games with UE4

By : William Sherif
Book Image

Learning C++ by creating games with UE4

By: William Sherif

Overview of this book

Table of Contents (19 chapters)
Learning C++ by Creating Games with UE4
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
2
Variables and Memory
Index

Creating non-player character entities


So, we need to create a few NPCs (non-playable characters). NPCs are characters within the game that help the player. Some offer special items, some are shop vendors, and some have information to give to the player. In this game, they will react to the player as he gets near. Let's program in some of this behavior.

First, create another subclass of Character. In the UE4 Editor, go to File | Add Code To Project... and choose the Character class from which you can make a subclass. Name your subclass NPC.

Now, edit your code in Visual Studio. Each NPC will have a message to tell the player, so we add in a UPROPERTY() FString property to the NPC class.

Note

FStrings are UE4's version of C++'s <string> type. When programming in UE4, you should use the FString objects over C++ STL's string objects. In general, you should preferably use UE4's built-in types, as they guarantee cross-platform compatibility.

How to add the UPROPERTY() FString property to the...