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...

  1. Create a new Actor class called Pickup.
  2. Declare the following delegate type in Pickup.h:
    DECLARE_DELEGATE(FPickedupEventSignature)
  3. Add the following properties to the class header:
    virtual void NotifyActorBeginOverlap(AActor* OtherActor) override;
    UPROPERTY()
    UStaticMeshComponent* MyMesh;
    
    UPROPERTY()
    URotatingMovementComponent* RotatingComponent;
    
    FPickedupEventSignatureOnPickedUp;
  4. 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.