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.
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"); RootComponent = MyMesh; auto MeshAsset = ConstructorHelpers::FObjectFinder<UStaticMesh>(TEXT("StaticMesh'/Engine/BasicShapes/Cube.Cube'")); if (MeshAsset.Object != nullptr) { MyMesh...