ASpawnVolume::ASpawnVolume(const class FPostConstructInitializeProperties& PCIP) : Super(PCIP) , m_isSpawningEnable(true) { m_WhereToSpawn = PCIP.CreateDefaultSubobject<UBoxComponent>(this, "WhereToSpawn"); RootComponent = m_WhereToSpawn; m_spawnDelayRangeLow = 1.f; m_spawnDelayRangeHigh = 4.5f; m_SpawnDelay = GetRandomSpawnDelay(); m_SpawnTime = 0; PrimaryActorTick.bCanEverTick = true; }
ASpawnVolume::ASpawnVolume(const class FPostConstructInitializeProperties& PCIP) : Super(PCIP) { /* Create a simple static mesh component to represent the pichup in the level */ WhereToSpawn = PCIP.CreateDefaultSubobject<UBoxComponent>(this, TEXT("WhereToSpawn")); /* Set the StaticMeshComponent as the root component */ RootComponent = WhereToSpawn; // Set the spawn delay range and get the first spawnDelay value SpawnDelayRangeLow = 1.0f; SpawnDelayRangeHigh = 4.5f; SpawnDelay = GetRandomSpawnDelay(); // Make this SpawnVolume tickable PrimaryActorTick.bCanEverTick = true; }
ASpawnVolume::ASpawnVolume(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer) { // Create the simple StaticMeshComponent to represent the pickup in the level WhereToSpawn = ObjectInitializer.CreateDefaultSubobject<UBoxComponent>(this, TEXT("WhereToSpawn")); // Set the StaticMeshComponent as the root component RootComponent = WhereToSpawn; // Set the spawn delay range and get the first SpawnDelay SpawnDelayRangeLow = 1.0f; SpawnDelayRangeHigh = 4.5f; SpawnDelay = GetRandomSpawnDelay(); // Make the spawn volume tickable. PrimaryActorTick.bCanEverTick = true; }
void ASpawnVolume::Tick(float DeltaSeconds) { if (m_isSpawningEnable) { m_SpawnTime += DeltaSeconds; bool bShouldSpawn = (m_SpawnTime > m_SpawnDelay); if (bShouldSpawn) { SpawnPickup(); m_SpawnTime -= m_SpawnDelay; m_SpawnDelay = GetRandomSpawnDelay(); } } }
void ASpawnVolume::Tick(float DeltaSeconds) { // If spawning is not enabled, do nothing if (!bSpawningEnabled) return; // Always add delta time to our Spawn Time SpawnTime += DeltaSeconds; bool bShouldSpawn = (SpawnTime > SpawnDelay); if (bShouldSpawn) { SpawnPickup(); // Deduct spawn delay from accumulated time value SpawnTime -= SpawnDelay; SpawnDelay = GetRandomSpawnDelay(); } }