Creating a respawning pickup for an First Person Shooter
This recipe shows you how to create a placeable pickup that will respawn after a certain amount of time, suitable as an ammo or other pickup for an FPS.
How to do it...
- Create a new
Actor
class calledPickup
. - Declare the following delegate type in
Pickup.h
:DECLARE_DELEGATE(FPickedupEventSignature)
- Add the following properties to the class header:
virtual void NotifyActorBeginOverlap(AActor* OtherActor) override; UPROPERTY() UStaticMeshComponent* MyMesh; UPROPERTY() URotatingMovementComponent* RotatingComponent; FPickedupEventSignatureOnPickedUp;
- Add the following code to the constructor:
MyMesh = CreateDefaultSubobject<UStaticMeshComponent>("MyMesh"); RotatingComponent = CreateDefaultSubobject<URotatingMovementComponent>("RotatingComponent"); ...
Get Unreal Engine 4 Scripting with C++ Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.