void AAgentSpawnerVolume::Tick(float DeltaSeconds) { Super::Tick(DeltaSeconds); if (m_spawnerActive == false) { return; } int32 numToSpawn = 0; m_timeSinceSpawn += DeltaSeconds; while (m_timeSinceSpawn >= m_spawnDelay) { numToSpawn++; m_timeSinceSpawn -= m_spawnDelay; } if (!m_endlessMode) { numToSpawn = FMath::Min(numToSpawn, m_numAgents - m_numAgentsSpawned); } FBox box = GetComponentsBoundingBox(); ABasicAIAgent *agent = Cast<ABasicAIAgent>(m_agentToSpawn.GetDefaultObject()); int32 agentTeam = agent->m_teamID; UFlockingDataCache *dataCache = UFlockingDataCache::GetCacheChecked(this); for (int32 i = 0; i < numToSpawn; i++) { if (!dataCache->IsTeamAtMaxSize(agentTeam)) { FVector point = FMath::RandPointInBox(FBox(box.Min, box.Max)); point.Z += agent->m_capsuleComponent->GetScaledCapsuleHalfHeight(); GetWorld()->SpawnActor(*m_agentToSpawn, &point, &FRotator::ZeroRotator, FActorSpawnParameters()); } m_numAgentsSpawned++; } }
AActor* UWeaponComponent::SpawnProjectile(UClass* ProjectileClass, FVector RelativeSpawnLocation, AActor* LaunchingActor, UGameplaySystemComponent* GameplaySystem) { FTransform SpawnTransform; { FRotator SpawnRotation = LaunchingActor->GetActorRotation(); FVector SpawnLocation = LaunchingActor->GetActorLocation(); SpawnLocation += SpawnRotation.RotateVector(RelativeSpawnLocation); SpawnTransform = FTransform(SpawnRotation, SpawnLocation); } FActorSpawnParameters SpawnParameters = FActorSpawnParameters(); SpawnParameters.Owner = this->GetOwner(); AActor* SpawnedActor = this->GetWorld()->SpawnActor(ProjectileClass, &SpawnTransform, SpawnParameters); AProjectile* Projectile = dynamic_cast<AProjectile*>(SpawnedActor); if (Projectile != nullptr) { Projectile->SetAttackPoints(GameplaySystem->GetInfightAttackPoints()); } return SpawnedActor; }
void AChangeable::Change() { FActorSpawnParameters SpawnParameters = FActorSpawnParameters(); SpawnParameters.bNoCollisionFail = true; APawn* Pawn = GetWorld()->SpawnActor<APawn>(TargetClass, GetActorLocation(), GetActorRotation(), SpawnParameters); if (Pawn) { if (Pawn->Controller) { Pawn->SpawnDefaultController(); } if (BehaviorTree != NULL) { AAIController* AIController = Cast<AAIController>(Pawn->Controller); if (AIController != NULL) { AIController->RunBehaviorTree(BehaviorTree); } } } Destroy(); }
void AOverlord::ServerPlaceTower_Implementation(FVector_NetQuantize location){ UWorld* const World = GetWorld(); if (World){ ASpawner* newActor = World->SpawnActor<ASpawner>(ASpawner::StaticClass(), location, (const FRotator)0, FActorSpawnParameters()); } }
void AWeapon::FireFunction(){ if (firedObject){ UWorld* world = GetWorld(); if (world){ FActorSpawnParameters parameters = FActorSpawnParameters(); parameters.bNoCollisionFail = true; parameters.Instigator = Owner; parameters.Name = GetProjectileName(); FVector spawnLocation = GetActorLocation(); FRotator spawnRotation = GetActorRotation(); AActor* Spawned = world->SpawnActor(*firedObject, &spawnLocation, &spawnRotation,parameters); AFirable* firable = Cast<AFirable>(Spawned); firable->SetColor(ProjectileColor); firable->Instigator = Owner->GetController(); firable->Damage = damage; firable->OwnerID = OwnerShipNumber; } } }