//Hides all the markers on the various game entities. void USpatialInterface::HideMarkers() { for (TActorIterator<AAsteroid> ActorItr(GWorld); ActorItr; ++ActorItr) { ActorItr->HideMarker(); } for (TActorIterator<AWayPoint> ActorItr(GWorld); ActorItr; ++ActorItr) { ActorItr->HideMarker(); } }
//Shows all the markers on the various game entities. void USpatialInterface::Tick(float DeltaTime) { for (TActorIterator<AAsteroid> ActorItr(GWorld); ActorItr; ++ActorItr) { ActorItr->ShowMarker(); } for (TActorIterator<AWayPoint> ActorItr(GWorld); ActorItr; ++ActorItr) { ActorItr->ShowMarker(); } }
FVector ARobot::getGoal2Position() { if (goal2 == NULL) { for (TActorIterator<AActor> ActorItr(GetWorld()); ActorItr; ++ActorItr) { //TODO: Improve finding goals! These name change if the goal is modified! if (ActorItr->GetName().Equals("football_goal_C_0") || ActorItr->GetName().Equals("football_goal_C_2")) { goal1 = Cast<AActor>(*ActorItr); } if (ActorItr->GetName().Equals("football_goal_C_1") || ActorItr->GetName().Equals("football_goal_C_3")) { goal2 = Cast<AActor>(*ActorItr); } } } if (goal2 != NULL) return goal2->GetActorLocation(); else return FVector(0, 0, 0); }
void UBuoyancyComponent::InitializeComponent() { Super::InitializeComponent(); // If no OceanManager is defined auto-detect if (!OceanManager) { for (TActorIterator<AOceanManager> ActorItr(GetWorld()); ActorItr; ++ActorItr) { OceanManager = Cast<AOceanManager>(*ActorItr); break; } } ApplyUprightConstraint(); TestPointRadius = FMath::Abs(TestPointRadius); //Signed based on gravity, just in case we need an upside down world _SignedRadius = FMath::Sign(GetGravityZ()) * TestPointRadius; if (UpdatedPrimitive->IsValidLowLevel()) { _baseLinearDamping = UpdatedPrimitive->GetLinearDamping(); _baseAngularDamping = UpdatedPrimitive->GetAngularDamping(); } }
void UBuoyancyForceComponent::InitializeComponent() { Super::InitializeComponent(); //UE_LOG(LogTemp, Warning, TEXT("We're initializing...")); //Store the world ref. World = GetWorld(); // If no OceanManager is defined, auto-detect if (!OceanManager) { for (TActorIterator<AOceanManager> ActorItr(World); ActorItr; ++ActorItr) { OceanManager = Cast<AOceanManager>(*ActorItr); break; } } TestPointRadius = FMath::Abs(TestPointRadius); UPrimitiveComponent* BasePrimComp = Cast<UPrimitiveComponent>(GetAttachParent()); if (BasePrimComp) { ApplyUprightConstraint(BasePrimComp); //Store the initial damping values. _baseLinearDamping = BasePrimComp->GetLinearDamping(); _baseAngularDamping = BasePrimComp->GetAngularDamping(); } }
void UAvoidanceComponent::Activate(bool bReset) { Super::Activate(); //UE_LOG(LogRVOTest, Warning, TEXT("uav: activate %p"), (void*)this); pawn = Cast<APawn>(GetOwner()); mc = pawn->GetMovementComponent(); for (TActorIterator<AActor> ActorItr(GetWorld()); ActorItr; ++ActorItr) { AActor* actor = *ActorItr; AORCAManager* orcaTest = Cast<AORCAManager>(actor); if (orcaTest) { manager = orcaTest; break; } } if (!manager) { UE_LOG(LogRVOTest, Warning, TEXT("You have to place an ORCAManager in the scene for the Aavoidance Component to work")); } else { manager->RegisterAvoidanceComponent(this); } }
void AMobileEnemy::Tick(float DeltaSeconds) { DeltaSeconds = TimeManager::Instance()->GetDeltaTime(DeltaSeconds); m_lastPosition = GetActorLocation(); m_nextPosition = m_lastPosition; EnemyAnimationMesh->bPauseAnims = TimeManager::Instance()->IsPaused(); if (!m_player) { for (TActorIterator< APawn > ActorItr(GetWorld()); ActorItr; ++ActorItr) { if (ActorItr->ActorHasTag("Player")) { m_player = (APlayerOvi*)*ActorItr; m_jumpSpeed = m_player->JumpSpeed; m_accelerationJump = m_player->AccelerationJump; break; } } } m_tickCounter++; if (!HasTrigger || (HasTrigger && m_initMovement)) { CheckCollision(); doMovement(DeltaSeconds); CalculateGravity(DeltaSeconds); CheckCollision(); SetActorLocation(m_nextPosition); } }
//overlap event (when the player drives through it) void ATimeGate::OnOverlapEnd(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex) { float playRate = 1.f; float colourDist = 100000.f; FLinearColor newColour = UKismetMathLibrary::MakeColor(UKismetMathLibrary::RandomFloatInRange(0.f, 1.f), UKismetMathLibrary::RandomFloatInRange(0.f, 1.f), UKismetMathLibrary::RandomFloatInRange(0.f, 1.f), 1.0f); UE_LOG(LogTemp, Log, TEXT("overlap begin!")); if (OtherActor->GetClass()->IsChildOf(ACar::StaticClass())) { UE_LOG(LogTemp, Log, TEXT("car overlap!")); IFYPGameEventInterface* TheInterface = NULL; TActorIterator< AActor > ActorItr(GetWorld()); while (ActorItr) { //Try casting to the interface TheInterface = Cast<IFYPGameEventInterface>(*ActorItr); //Run the Event specific to the actor, if the actor has the interface if (TheInterface) { TheInterface->GateReached_Implementation(newColour, playRate, colourDist); } ++ActorItr; } UE_LOG(LogTemp, Warning, TEXT("destroying gate")); this->Destroy(); } }
void AHeatmapDataCollector::CollectCharacters() { if (cWorld) { for (TActorIterator<ACharacter> ActorItr(cWorld); ActorItr; ++ActorItr) { ATDownCharacter* foundedCh = Cast<ATDownCharacter>(*ActorItr); //auto isChr = foundedCh->GetClass()->IsChildOf(ATDownCharacter::StaticClass()); if (foundedCh) { CharactersArr.Add(foundedCh); } } } if (CharNumberInWorld < CharactersArr.Num()) { auto selectChar = Cast<ATDownCharacter>(CharactersArr[CharNumberInWorld]); if (selectChar) { if (!CharCurrentPtr) { SetCharacter(selectChar); // Set pointer to Character fom CharNumberInWorld } } } }
void AEventExampleProjectPlayerController::BeginPlay() { if (GetWorld() != nullptr) { // iterate over all actors in the world for (TActorIterator<AActor> ActorItr(GetWorld()); ActorItr; ++ActorItr) { // is this actor an AI controller? if so, we need to store a weak pointer to it AAIController * pController = Cast<AAIController>(*ActorItr); if (pController) { // this is an AIController, so store the weak pointer to it so we can use it later TWeakObjectPtr<AAIController> wptr = TWeakObjectPtr<AAIController>(pController); ControlledActors.Add(wptr); } else { RegisterSelectableActorCallback(*ActorItr); } } // bind an event on the world so that any new actors that are spawned we get a chance to see if they have USelectableComponent and bind those too!! FOnActorSpawned::FDelegate ActorSpawnedDelegate = FOnActorSpawned::FDelegate::CreateUObject(this,&AEventExampleProjectPlayerController::RegisterSelectableActorCallback); GetWorld()->AddOnActorSpawnedHandler(ActorSpawnedDelegate); } }
AActor * ASDBXGameMode::ChoosePlayerStart_Implementation(AController * Player){ APlayerStart * player1Spawn = NULL; APlayerStart * player2Spawn = NULL; APlayerStart * startToSpawnAt = NULL; //player start tags FString tag1 = "0"; FString tag2 = "1"; for (TActorIterator<APlayerStart> ActorItr(GetWorld()); ActorItr; ++ActorItr){ if (ActorItr->PlayerStartTag == FName(*tag1)){ player1Spawn = *ActorItr; } else if (ActorItr->PlayerStartTag == FName(*tag2)){ player2Spawn = *ActorItr; } } if (player1Spawn && !firstPlayerSpawned){ startToSpawnAt = player1Spawn; firstPlayerSpawned = true; } else if (player2Spawn && firstPlayerSpawned){ startToSpawnAt = player2Spawn; } return startToSpawnAt ? startToSpawnAt : Super::ChoosePlayerStart_Implementation(Player); }
void AMeshWallText::Cleanup(UWorld* World) { MeshPool.Empty(); // destroy all actors of this class for (TActorIterator<AMeshWallText> ActorItr(World); ActorItr; ++ActorItr) { ActorItr->Destroy(); } }
void AFrisbeeNulPlayerController::BeginPlay() { for (TActorIterator<AFrisbee> ActorItr(GetWorld()); ActorItr; ++ActorItr) { GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Blue, ActorItr->GetName()); this->frisbee = *ActorItr; } }
void ALivingBomb::ClientDestroyTerrain_Implementation(FVector location, float radius) { for (TActorIterator<ATerrainManager> ActorItr(GetWorld()); ActorItr; ++ActorItr) { ATerrainManager * voxelVolume = (ATerrainManager*)(*ActorItr); voxelVolume->EditVolume(location, radius, false); //voxelVolume->ExecAddMesh(SpawnLocation, 10.0f); } }
void ATotemCharacter::ClientDestroyTerrain_Implementation(FVector location, float radius) { //UE_LOG(LogTemp, Warning, TEXT("ClientDestroyTerrain_Implementation (FireBall): %s, radius : %f"), *location.ToString(), radius); for (TActorIterator<ATerrainManager> ActorItr(GetWorld()); ActorItr; ++ActorItr) { ATerrainManager * voxelVolume = (ATerrainManager*)(*ActorItr); voxelVolume->EditVolume(location, radius, false); //voxelVolume->ExecAddMesh(SpawnLocation, 10.0f); } }
void AQuestGiver::Tick(float deltatime) { Super::Tick(deltatime); for (TActorIterator<AAlistair> ActorItr(GetWorld()); ActorItr; ++ActorItr) { if (ActorItr->QuestsCompleted >= NumQuestsNeeded && QuestState == LOCKED) { QuestState = NOTTAKEN; } } }
void StunPowerUp::Over() { for (TActorIterator<ABouncerPlayer> ActorItr(WorldRef); ActorItr; ++ActorItr) { if (*ActorItr != Owner) { ActorItr->StunIsOver(); if (ActorItr->GetStunnedCounter() <= 0) ActorItr->SetStunned(false); } } }
void ARobot::speak(FString text) { //Speak to all Robots: for (TActorIterator<ARobot> ActorItr(GetWorld()); ActorItr; ++ActorItr) { ARobot* robot = Cast<ARobot>(*ActorItr); if (this == robot) continue; robot->listen(text); } }
void AAmbitionOfNobunagaPlayerController::BeginPlay() { Hud = Cast<ARTS_HUD>(UGameplayStatics::GetPlayerController(this, 0)->GetHUD()); Hud->localController = this; bMouseRButton = false; bMouseLButton = false; for(TActorIterator<AActor> ActorItr(GetWorld()); ActorItr; ++ActorItr) { if(*ActorItr != this) { ActorItr->SetOwner(this); } } }
void UBTComposite_Question::SetVisibility(APlayerController* PlayerController, bool NewVisibility) const { if (DialogueSettings != NULL && !SettingName.EqualTo(FText::FromString("None"))) { for (TActorIterator<ADialogueSettings> ActorItr(GetWorld()); ActorItr; ++ActorItr) { ADialogueSettings *Settings = *ActorItr; if (Settings->PlayerController == PlayerController) { return Settings->SetPropertyBoolValue(SettingName.ToString(), NewVisibility); } } } }
// Called when the game starts or when spawned void APoseidonCharacter::BeginPlay() { Super::BeginPlay(); GetCharacterMovement()->MaxWalkSpeed = MovementSpeed; CameraManager = GEngine->GetFirstLocalPlayerController(GetWorld())->PlayerCameraManager; CameraManager->ViewPitchMax = 40.0f; CameraManager->ViewPitchMin = -60.0f; PlayerCamera->FieldOfView = mFieldOfView; //Initialize player HUD PlayerHUD = Cast<APoseidonHUD>(GetWorld()->GetFirstPlayerController()->GetHUD()); //Cone start On Overlap functions if (Cone) { Cone->OnComponentBeginOverlap.AddDynamic(this, &APoseidonCharacter::OnOverlapBegin); Cone->OnComponentEndOverlap.AddDynamic(this, &APoseidonCharacter::OnOverlapEnd); } PlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 0); AnimationBP = GetMesh()->GetAnimInstance(); int uiManagersInScene = 0; for (TActorIterator<AUIManager> ActorItr(GetWorld()); ActorItr; ++ActorItr) { if (uiManagersInScene == 1) { AUIManager* UI = Cast<AUIManager>(*ActorItr); UI->Destroy(); continue; } uiManagersInScene++; } if (uiManagersInScene == 0) { FActorSpawnParameters SpawnParams; SpawnParams.Instigator = this; FVector Location = FVector(0.f, 0.f, 0.f); FRotator Rotation = FRotator(); UIManagerInstance = GetWorld()->SpawnActor<AUIManager>(UIManager, Location, Rotation, SpawnParams); } }
// Revive Player void ARadeCharacter::Revive() { // Enable Input EnableInput(Cast<APlayerController>(Controller)); // Set Camer to Default Camera state CurrentCameraState = DefaultCameraState; // Resoter Half of player health Health = MaxHealth/2; bDead = false; // Restore Third Person Mesh to default State if (GetMesh()) { GetMesh()->SetSimulatePhysics(false); GetMesh()->AttachTo(RootComponent); GetMesh()->RelativeLocation = Mesh_InGameRelativeLoc; GetMesh()->RelativeRotation = Mesh_InGameRelativeRot; GetMesh()->BodyInstance.SetCollisionProfileName("Pawn"); } // Find The Closest Revive Point TActorIterator<APlayerStart> p(GetWorld()); APlayerStart* revivePoint = *p; for (TActorIterator<APlayerStart> ActorItr(GetWorld()); ActorItr; ++ActorItr) { if (revivePoint && FVector::Dist(revivePoint->GetActorLocation(), GetActorLocation())> FVector::Dist(ActorItr->GetActorLocation(), GetActorLocation())) { revivePoint = *ActorItr; } } UpdateComponentsVisibility(); // Create a small offset from the spawn point if (revivePoint) GetRootComponent()->SetWorldLocation(revivePoint->GetActorLocation() + FVector(FMath::RandRange(-400, 400), FMath::RandRange(-400, 400), 60)); //GetMovementComponent()->Activate(); // Call Revive on Blueprint BP_PlayerRevived(); }
void ASpaceHuntingGameMode::InitializeGame() { // Setup spaceship APawn* PlayerPawn = GetWorld()->GetFirstPlayerController()->GetPawn(); Spaceship = Cast<ASpaceship>(PlayerPawn); if (Spaceship == nullptr) UE_LOG(LogTemp, Warning, TEXT("GAME_MODE: Spaceship not found")); // Setup Mothership for (TActorIterator<AMothershipEnemy> ActorItr(GetWorld()); ActorItr; ++ActorItr) { Mothership = *ActorItr; UE_LOG(LogTemp, Warning, TEXT("GAME_MODE: name: %s"), *(Mothership->GetName())); } }
/******************** GetNearestStructure *************************/ APOTLStructure* APOTLStructure::GetNearestStructure() { APOTLStructure* NearestStructure = nullptr; //TSubclassOf<AActor> ClassToFind; //Array<AActor*> FoundActors; //UGameplayStatics::GetAllActorsOfClass(GetWorld(), ClassToFind, FoundActors); for (TActorIterator<APOTLStructure> ActorItr(GetWorld()); ActorItr; ++ActorItr) { //ClientMessage(ActorItr->GetName()); //ClientMessage(ActorItr->GetActorLocation().ToString()); GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, ActorItr->GetName()); } return NearestStructure; }
//when the player fails to reach this gate when its active void ATimeGate::AlertRoundEnd() { //Actor iterator from https://wiki.unrealengine.com/Interfaces_in_C%2B%2B#Creating_Global_Events IFYPGameEventInterface* TheInterface = NULL; TActorIterator< AActor > ActorItr(GetWorld()); while (ActorItr) { //Try casting to the interface TheInterface = Cast<IFYPGameEventInterface>(*ActorItr); //Run the Event specific to the actor, if the actor has the interface if (TheInterface) { TheInterface->RoundEnd_Implementation(); } ++ActorItr; } }
void StunPowerUp::Use(UWorld* WorldRef) { BouncerPowerUp::Use(WorldRef); this->WorldRef = WorldRef; Owner->SetTimer(STUN_LENGTH); for (TActorIterator<ABouncerPlayer> ActorItr(WorldRef); ActorItr; ++ActorItr) { if (*ActorItr != Owner) { if (!ActorItr->IsInvinsible()) { ActorItr->GotStunned(); ActorItr->SetStunned(true); } } } }
void AMyGameMode::RestoreLevel(bool checkPoint) { if (checkPoint) { m_actualPoints = m_actualCheckPoint.Points; m_countOrbs = m_actualCheckPoint.Orbs; m_player->ResetToCheckPoint(m_actualCheckPoint.PlayerStatus, m_actualCheckPoint.PlayerToRight); m_player->SetKey(m_actualCheckPoint.PlayerHasKey, m_actualCheckPoint.ColorKey); state = EndGameType::NONE; //prueba de restaurar item cogidos despues del checkpoint /*Si los he cogido y no estan en el array almacenado los restauro*/ for (TActorIterator<APickableItem> ActorItr(GetWorld()); ActorItr; ++ActorItr) { if (ActorItr->IsItemPicked()) { if (m_actualCheckPoint.ItemsPicked.Find(*ActorItr) == INDEX_NONE) { (*ActorItr)->RestoreInitialPosition(); } } } } }
TArray<RobotDataTypes::PlayerLocation>* ARobot::getVisiblePlayers() { FVector ownLocation = GetActorLocation(); FRotator ownRotation = GetActorRotation(); TArray<RobotDataTypes::PlayerLocation>* visiblePlayerLocations = new TArray<RobotDataTypes::PlayerLocation>(); //Iterate through all Robots for (TActorIterator<ARobot> ActorItr(GetWorld()); ActorItr; ++ActorItr) { ARobot* robot = Cast<ARobot>(*ActorItr); if (this == robot) continue; if (isObjectVisible(robot->getPosition())) { visiblePlayerLocations->Add(RobotDataTypes::PlayerLocation{ robot->getTeamId(), robot->getPlayerId(), new FVector(robot->getPosition()) }); } } return visiblePlayerLocations; }
EBTNodeResult::Type UFindEnemyTask::ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory) { if (!GetWorld()) { return EBTNodeResult::Failed; } for (TActorIterator<AMyCharacter> ActorItr(GetWorld()); ActorItr; ++ActorItr) { AMyCharacter* PlayerCharacter = *ActorItr; if (PlayerCharacter) { OwnerComp.GetBlackboardComponent()->SetValue<UBlackboardKeyType_Object>( BlackboardKey.GetSelectedKeyID(), PlayerCharacter); return EBTNodeResult::Succeeded; } } return EBTNodeResult::Failed; }
void AMobilePlatform::Tick(float DeltaSeconds) { DeltaSeconds = TimeManager::Instance()->GetDeltaTime(DeltaSeconds); Super::Tick(DeltaSeconds); if (Enabled) { if (!m_player) for (TActorIterator< APawn > ActorItr(GetWorld()); ActorItr; ++ActorItr) if (ActorItr->ActorHasTag("Player")){ m_player = (APlayerOvi*)*ActorItr; //break; } m_controlOff = false; doMovement(DeltaSeconds); if (m_player && m_isPlayerOn) m_player->OnMobilePlatform(this, m_movement); } else { if (!m_controlOff) { m_controlOff = true; MobilePlatformMaterial->SetVectorParameterValue("Color", ColorDisabled); // I think this functions is worst than an 'if' } } }