Pickup.h
// return the mesh for the pickup
FORCEINLINE class UStaticMeshComponent* GetMesh() const { return PickupMesh; }
private:
// static mesh to represent the pickup in the level*/
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category= "Pickup", meta=(AllowPrivateAccess= true))
class UStaticMeshComponent * PickupMesh;
Pickup.cpp
PrimaryActorTick.bCanEverTick = false;
// create the static mesh component
PickupMesh = CreateDefaultSubobject(TEXT("PickupMesh"));
RootComponent = PickupMesh;
Pickup.h
// return th value of bIsActive
UFUNCTION(BlueprintPure, Category="Pickup")
bool IsActive();
// set the value of bIsActive
UFUNCTION(BlueprintCallable, Category="Pickup")
void SetActive(bool NewPickupState);
Pickup.cpp
// return active state
bool APickup::IsActive() {
return bIsActive;
}
// change active state.
void APickup::SetActive(bool NewPickupState) {
bIsActive = NewPickupState;
return;
}
BatteryPickup.h
ABatteryPickup();
BatteryPickup.C
// set default value
ABatteryPickup::ABatteryPickup() {
GetMesh()->SetSimulatePhysics(true);
UE_LOG(LogTemp, Warning,TEXT("I Am in the Contstructor Yes I am"));
}
SpawnVolume.h
FORCEINLINE class UBoxComponent * GetWhereToSpawn() const { return WhereToSpawn; }
// generate a random point to generate the items.
UFUNCTION(BlueprintPure, Category= "Spawning")
FVector GetRandomPontInVolume();
private:
// the boxl componenet to specify where pickups should be spawned.
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Spawning", meta = (AllowPrivateAccess = "true"))
class UBoxComponent * WhereToSpawn;
};
SpawnVolume.cpp
#include "Kismet/KismetMathLibrary.h"
...
FVector ASpawnVolumn::GetRandomPontInVolume() {
FVector SpawnOrigin = WhereToSpawn->Bounds.Origin;
FVector SpawnExtent = WhereToSpawn->Bounds.BoxExtent;
return UKismetMathLibrary::RandomPointInBoundingBox(SpawnOrigin, SpawnExtent);
}