void AZombieCharacter::DisableDotEffectIfNecessary(bool ForceStop) { //Disables the dot effect is necessary (ie dot timer has been depleted) //If ForceStop is active it forces the dot effect to stop even if the dot timer is still active UWorld* World = GetWorld(); //Forced stop of dot effect if (ForceStop && World && OurCharacter && World->GetTimerManager().IsTimerActive(DotTimerHandle)) { GLog->Log("Stopping Dot Effect..."); World->GetTimerManager().ClearTimer(DotTimerHandle); ParticleSystemComponent->Deactivate(); //ZombieDebuffComp->SetFireParticleEnabled(false); bHasDot = false; } else { //Disable effect due to time out if (World && OurCharacter && World->GetTimerManager().IsTimerActive(DotTimerHandle) && World->GetTimeSeconds() - DotApplicationTime>=OurCharacter->DotDuration) { World->GetTimerManager().ClearTimer(DotTimerHandle); ParticleSystemComponent->Deactivate(); //ZombieDebuffComp->SetFireParticleEnabled(false); bHasDot = false; } } //ParticleSystemComponent->Deactivate(); }
void UGameplayTask_WaitDelay::Activate() { UWorld* World = GetWorld(); TimeStarted = World->GetTimeSeconds(); // Use a dummy timer handle as we don't need to store it for later but we don't need to look for something to clear FTimerHandle TimerHandle; World->GetTimerManager().SetTimer(TimerHandle, this, &UGameplayTask_WaitDelay::OnTimeFinish, Time, false); }
void AZombieCharacter::ApplyDotEffect(float DamageAmount) { //Applies the damage over time effect on zombie and sets up the corresponding particle template //Moreover, initializes the dot timer handle so certain damage is applied over-time. if (!bHasDot) { AZombieController* ZCon = Cast<AZombieController>(GetController()); if (ZCon) { //Calculating the tick damage that we're going to apply in the zombie //based on the given damage amount. float DotTimer = OurCharacter->DotDuration; float TickDamage = DamageAmount / DotTimer; //The delegate that is binded to the apply damage function FTimerDelegate Delegate; Delegate.BindUFunction<AZombieCharacter, float>(this, FName("ApplyDamage"), TickDamage); //Enabling the dot effect.. UWorld* World = GetWorld(); if (World && OurCharacter) { World->GetTimerManager().SetTimer(DotTimerHandle, Delegate, DotTickInSeconds, true); DotApplicationTime = World->GetTimeSeconds(); GLog->Log("Dot application seconds:" + FString::SanitizeFloat(DotApplicationTime)); bHasDot = true; //Resets the particle system template if(ParticleSystemComponent) { ParticleSystemComponent->SetTemplate(FireEffectParticleTemplate); ParticleSystemComponent->Activate(true); //Activate the fire particles /*ParticleSystemComponent->Deactivate(); ParticleSystemComponent->Template = FireEffectParticleTemplate; ParticleSystemComponent->Activate(true);*/ //ZombieDebuffComp->SetFireParticleEnabled(true); } } } } }
void UGAWaitAction::Activate() { OnInitialized.Broadcast(); if (GEngine) { GEngine->AddOnScreenDebugMessage(0, 1, FColor::Red, FString("ObjectName: ") + GetName()); } if (TaskOwner && TaskOwner->GetWorld()) { UWorld* World = TaskOwner->GetWorld(); TimeStarted = World->GetTimeSeconds(); // Use a dummy timer handle as we don't need to store it for later but we don't need to look for something to clear FTimerHandle TimerHandle; World->GetTimerManager().SetTimer(TimerHandle, this, &UGAWaitAction::OnTimeFinish, Time, false); } }
void AMainCharacter::StartFire() { UWorld* World = GetWorld(); if (World) { if (CurrentWeapon != NULL) { if (CurrentWeapon->Config.bIsAutomatic == true) { World->GetTimerManager().SetTimer( AutomaticFireTimerHandle, this, &AMainCharacter::FireWeapon, CurrentWeapon->Config.FireRate, true, 0.0f); } else if (bFireIsReady) { World->GetTimerManager().ClearTimer(SingleFireTimerHandle); World->GetTimerManager().SetTimer( SingleFireTimerHandle, this, &AMainCharacter::FireIsReady, CurrentWeapon->Config.FireRate, true, CurrentWeapon->Config.FireRate); FireWeapon(); bFireIsReady = false; } } } }
class UKismetAIAsyncTaskProxy* UKismetAIHelperLibrary::CreateMoveToProxyObject(class UObject* WorldContextObject, APawn* Pawn, FVector Destination, AActor* TargetActor, float AcceptanceRadius, bool bStopOnOverlap) { check(WorldContextObject); if (!Pawn) { return NULL; } UKismetAIAsyncTaskProxy* MyObj = NULL; AAIController* AIController = Cast<AAIController>(Pawn->GetController()); if (AIController) { MyObj = NewObject<UKismetAIAsyncTaskProxy>(); FNavPathSharedPtr Path = TargetActor ? AIController->FindPath(TargetActor, true) : AIController->FindPath(Destination, true); if (Path.IsValid()) { MyObj->AIController = AIController; MyObj->AIController->ReceiveMoveCompleted.AddDynamic(MyObj, &UKismetAIAsyncTaskProxy::OnMoveCompleted); MyObj->MoveRequestId = MyObj->AIController->RequestMove(Path, TargetActor, AcceptanceRadius, bStopOnOverlap); } else { UWorld* World = GEngine->GetWorldFromContextObject( WorldContextObject ); World->GetTimerManager().SetTimer(MyObj, &UKismetAIAsyncTaskProxy::OnNoPath, 0.1, false); } } return MyObj; }
void AZombieCharacter::ApplySlowEffect() { //Applies the slow effect on zombie and sets up the slow timer //as well as the right particle template if (!bHasSlow) { DisableDotEffectIfNecessary(true); bHasSlow = true; float SlowSpeed = InitialMaxWalkSpeed * (1 - SlowPercentage); //Activating slow GetCharacterMovement()->MaxWalkSpeed = SlowSpeed; //Reseting the slow particle template ParticleSystemComponent->SetTemplate(SlowEffectParticleTemplate); ParticleSystemComponent->Activate(true); GLog->Log("Applied slow effect on zombie."); //Initializing the slow timer handle UWorld* World = GetWorld(); if (World && OurCharacter) { World->GetTimerManager().SetTimer(SlowTimerHandle, this, &AZombieCharacter::DisableSlowEffect, SlowEffectDuration); } } }
void ANetworkController::BeginPlay() { // TODO: Move this to a more fitting place FMath::RandInit(FPlatformTime::Cycles()); FMath::SRandInit(FPlatformTime::Cycles()); FIPv4Address Address = FIPv4Address::InternalLoopback; uint32 Port = 5062; TcpServerSocket = FTcpSocketBuilder(TEXT("Controlling TCP Socket")) .AsReusable() .AsNonBlocking() .BoundToAddress(Address) .BoundToPort(Port) .Listening(8) .Build(); int32 NewSize = 0; TcpServerSocket->SetReceiveBufferSize(2 * 1024 * 1024, NewSize); if (!TcpServerSocket) { GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("Listen socket could not be created! ~> %s %d"), *Address.ToText().ToString(), Port)); return; } Listener = new FTcpListener(*TcpServerSocket); Listener->OnConnectionAccepted().BindUObject(this, &ANetworkController::ConnectionAccepted); //GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, FString::Printf(TEXT("Listening to %s:%d"), *Address.ToText().ToString(), Port)); UWorld* World = GetWorld(); World->GetTimerManager().SetTimer(SendDataTimerHandle, this, &ANetworkController::SendData, 1.0f, true); }
void APartyBeaconHost::NotifyReservationEventNextFrame(FOnReservationUpdate& ReservationEvent) { UWorld* World = GetWorld(); check(World); // Calling this on next tick to protect against re-entrance World->GetTimerManager().SetTimerForNextTick(FTimerDelegate::CreateLambda([ReservationEvent](){ ReservationEvent.ExecuteIfBound(); })); }
void AbortLatentActions(UActorComponent* OwnerOb, const UObject* Ob) { if (OwnerOb && !OwnerOb->HasAnyFlags(RF_BeginDestroyed) && OwnerOb->GetOwner()) { UWorld* MyWorld = OwnerOb->GetOwner()->GetWorld(); MyWorld->GetLatentActionManager().RemoveActionsForObject(Ob); MyWorld->GetTimerManager().ClearAllTimersForObject(Ob); } }
void AMainCharacter::EndFire() { UWorld* World = GetWorld(); if (World) { World->GetTimerManager().PauseTimer(AutomaticFireTimerHandle); World->GetTimerManager().ClearTimer(AutomaticFireTimerHandle); } }
void UAvoidanceManager::RequestUpdateTimer() { UWorld* MyWorld = Cast<UWorld>(GetOuter()); if (!bRequestedUpdateTimer && MyWorld) { bRequestedUpdateTimer = true; MyWorld->GetTimerManager().SetTimer(TimerHandle_RemoveOutdatedObjects, this, &UAvoidanceManager::RemoveOutdatedObjects, DefaultTimeToLive * 0.5f, false); } }
FTimerHandle UUpdateManager::DelayResponse(DelayCb&& Delegate, float Delay) { FTimerHandle TimerHandle; UWorld* World = GetWorld(); if (ensure(World != nullptr)) { World->GetTimerManager().SetTimer(TimerHandle, MoveTemp(Delegate), Delay, false, -1.f); } return TimerHandle; }
void AZanshinBasicArrow::StuckOnPlayer(UPrimitiveComponent* OtherComp) { if (OtherComp != NULL) { RootComponent->AttachTo(OtherComp, FName(*OtherComp->GetName()), EAttachLocation::KeepWorldPosition); } //Timer for the Deactivation UWorld* World = GetWorld(); if (World) { World->GetTimerManager().SetTimer(DeactivateTimerHandle, this, &AZanshinBasicArrow::NetMulticast_DeactivateTrails, DeactivationDelay); } }
void ANetworkController::EndPlay(const EEndPlayReason::Type EndPlayReason) { UWorld* World = GetWorld(); World->GetTimerManager().ClearTimer(SendDataTimerHandle); Listener->Stop(); delete Listener; Listener = NULL; TcpServerSocket->Close(); if (TcpSocket) { TcpSocket->Close(); } }
bool AGameplayCueNotify_Actor::Recycle() { bHasHandledOnActiveEvent = false; bHasHandledWhileActiveEvent = false; bHasHandledOnRemoveEvent = false; ClearOwnerDestroyedDelegate(); if (FinishTimerHandle.IsValid()) { FinishTimerHandle.Invalidate(); } // End timeline components TInlineComponentArray<UTimelineComponent*> TimelineComponents(this); for (UTimelineComponent* Timeline : TimelineComponents) { if (Timeline) { // May be too spammy, but want to call visibility to this. Maybe make this editor only? if (Timeline->IsPlaying()) { ABILITY_LOG(Warning, TEXT("GameplayCueNotify_Actor %s had active timelines when it was recycled."), *GetName()); } Timeline->SetPlaybackPosition(0.f, false, false); Timeline->Stop(); } } UWorld* MyWorld = GetWorld(); if (MyWorld) { // Note, ::Recycle is called on CDOs too, so that even "new" GCs start off in a recycled state. // So, its ok if there is no valid world here, just skip the stuff that has to do with worlds. if (MyWorld->GetLatentActionManager().GetNumActionsForObject(this)) { // May be too spammy, but want ot call visibility to this. Maybe make this editor only? ABILITY_LOG(Warning, TEXT("GameplayCueNotify_Actor %s has active latent actions (Delays, etc) when it was recycled."), *GetName()); } // End latent actions MyWorld->GetLatentActionManager().RemoveActionsForObject(this); // End all timers MyWorld->GetTimerManager().ClearAllTimersForObject(this); } // Clear owner, hide, detach from parent SetOwner(nullptr); SetActorHiddenInGame(true); DetachRootComponentFromParent(); return true; }
void AWeapon::Fire(){ if (bCanFire){ if (FireSound) UGameplayStatics::PlaySoundAtLocation(this, FireSound, GetActorLocation()); bIsFiring = true; FireFunction(); bCanFire = false; UWorld* world = GetWorld(); if (world){ world->GetTimerManager().SetTimer(TimerHandle_ShotIntervalExpired, this, &AWeapon::Reload, intervalBetweenFire); } } }
void AZanshinAIController::OnPullString() { AZanshinBot* character = Cast<AZanshinBot>(GetPawn()); if (character) { character->OnPullString(); UWorld* World = GetWorld(); if (World) { PullStringTime = 0.15f; World->GetTimerManager().SetTimer(PullStringTimerHandle, this, &AZanshinAIController::OnFire, PullStringTime); } } }
void AMainCharacter::EquipWeapon(int32 NewInventorySlot) { UWorld* World = GetWorld(); World->GetTimerManager().PauseTimer(AutomaticFireTimerHandle); World->GetTimerManager().ClearTimer(AutomaticFireTimerHandle); FActorSpawnParameters SpawnParameters; SpawnParameters.Owner = this; SpawnParameters.Instigator = Instigator; if (CurrentWeapon != NULL) { if (Inventory[NewInventorySlot] != NULL) { if (Inventory[NewInventorySlot]->GetDefaultObject<AWeapon>()->Config.Name != CurrentWeapon->Config.Name) { WeaponAmmoStorage[CurrentInventorySlot].CurrentSpareAmmo = CurrentWeapon->Config.CurrentSpareAmmo; WeaponAmmoStorage[CurrentInventorySlot].CurrentMagazineAmmo = CurrentWeapon->Config.CurrentMagazineAmmo; CurrentWeapon->Destroy(); AWeapon* Spawner = GetWorld()->SpawnActor<AWeapon>(Inventory[NewInventorySlot], SpawnParameters); if (Spawner != nullptr) { Spawner->CollisionComponent->SetCollisionEnabled(ECollisionEnabled::NoCollision); Spawner->AttachRootComponentTo(FirstPersonMesh, "Equip", EAttachLocation::SnapToTarget); CurrentWeapon = Spawner; if (WeaponAmmoStorage[NewInventorySlot].CurrentSpareAmmo != -1 && WeaponAmmoStorage[NewInventorySlot].CurrentMagazineAmmo != -1) { CurrentWeapon->Config.CurrentSpareAmmo = WeaponAmmoStorage[NewInventorySlot].CurrentSpareAmmo; CurrentWeapon->Config.CurrentMagazineAmmo = WeaponAmmoStorage[NewInventorySlot].CurrentMagazineAmmo; } CurrentInventorySlot = NewInventorySlot; } } else { GEngine->AddOnScreenDebugMessage(0, 5.f, FColor::Yellow, "Weapon is already equiped!"); } } } else { AWeapon* Spawner = GetWorld()->SpawnActor<AWeapon>(Inventory[NewInventorySlot], SpawnParameters); if (Spawner) { Spawner->CollisionComponent->SetCollisionEnabled(ECollisionEnabled::NoCollision); Spawner->AttachRootComponentTo(FirstPersonMesh, "Equip", EAttachLocation::SnapToTarget); CurrentWeapon = Spawner; CurrentInventorySlot = NewInventorySlot; } } }
UAIAsyncTaskBlueprintProxy* UAIBlueprintHelperLibrary::CreateMoveToProxyObject(UObject* WorldContextObject, APawn* Pawn, FVector Destination, AActor* TargetActor, float AcceptanceRadius, bool bStopOnOverlap) { check(WorldContextObject); if (!Pawn) { return NULL; } UAIAsyncTaskBlueprintProxy* MyObj = NULL; AAIController* AIController = Cast<AAIController>(Pawn->GetController()); if (AIController) { UWorld* World = GEngine->GetWorldFromContextObject( WorldContextObject ); MyObj = NewObject<UAIAsyncTaskBlueprintProxy>(World); FAIMoveRequest MoveReq; MoveReq.SetUsePathfinding(true); MoveReq.SetAcceptanceRadius(AcceptanceRadius); MoveReq.SetStopOnOverlap(bStopOnOverlap); if (TargetActor) { MoveReq.SetGoalActor(TargetActor); } else { MoveReq.SetGoalLocation(Destination); } FPathFindingQuery Query; const bool bValidQuery = AIController->PreparePathfinding(MoveReq, Query); if (bValidQuery) { const FAIRequestID RequestID = AIController->RequestPathAndMove(MoveReq, Query); if (RequestID.IsValid()) { MyObj->AIController = AIController; MyObj->AIController->ReceiveMoveCompleted.AddDynamic(MyObj, &UAIAsyncTaskBlueprintProxy::OnMoveCompleted); MyObj->MoveRequestId = RequestID; } else { World->GetTimerManager().SetTimer(MyObj->TimerHandle_OnNoPath, MyObj, &UAIAsyncTaskBlueprintProxy::OnNoPath, 0.1f, false); } } } return MyObj; }
void UFunctionalTestingManager::TriggerFirstValidTest() { UWorld* World = GetWorld(); bIsRunning = World != NULL && World->GetNavigationSystem() != NULL; if (bInitialDelayApplied == true && (bWaitForNavigationBuildFinish == false || UNavigationSystem::IsNavigationBeingBuilt(World) == false)) { bIsRunning = RunFirstValidTest(); if (bIsRunning == false) { AllTestsDone(); } } else { bInitialDelayApplied = true; static const float WaitingTime = 0.25f; World->GetTimerManager().SetTimer(this, &UFunctionalTestingManager::TriggerFirstValidTest, WaitingTime); } }
void AGameplayCueNotify_Actor::GameplayCueFinishedCallback() { UWorld* MyWorld = GetWorld(); if (MyWorld) // Teardown cases in PIE may cause the world to be invalid { if (FinishTimerHandle.IsValid()) { MyWorld->GetTimerManager().ClearTimer(FinishTimerHandle); FinishTimerHandle.Invalidate(); } // Make sure OnRemoved has been called at least once if WhileActive was called (for possible cleanup) if (bHasHandledWhileActiveEvent && !bHasHandledOnRemoveEvent) { // Force onremove to be called with null parameters bHasHandledOnRemoveEvent = true; OnRemove(nullptr, FGameplayCueParameters()); } } UAbilitySystemGlobals::Get().GetGameplayCueManager()->NotifyGameplayCueActorFinished(this); }