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.
Tip
FString
s 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...