Unreal Engine 4.x Scripting with C++ Cookbook - Second Edition
by John P. Doran, William Sherif, Stephen Whittle
How it works...
First, we create the barracks actor. We add a particle system component to indicate where the new units will be spawning and a static mesh for the visual representation of the building.
In the constructor, we initialize the components and then set their values using FObjectFinder. We also set the class to spawn using the StaticClass function to retrieve a UClass* instance from a class type.
In the BeginPlay function of the barracks, we create a timer that calls our SpawnUnit function at fixed intervals. We store the timer handle in a member variable in the class so that when our instance is being destroyed, we can halt the timer; otherwise, when the timer triggers again, we'll encounter a crash where the object pointer is ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access