void ACharacterTargetSystem::cleanUpTargets(UWorld* currentGameWorld) { // clean up all previous focused enemies for (TObjectIterator<ABasicEnemy> enemyFocusIterator; enemyFocusIterator; ++enemyFocusIterator) { if (enemyFocusIterator->GetWorld() == currentGameWorld) { ABasicEnemy* enemyChar = *enemyFocusIterator; if (!enemyChar->IsPendingKill()) { enemyChar->hideFocusComponent(); enemyChar->removeFocus(); enemyChar->disableMenu(); } } } // clean up all previous focused enemies for (TObjectIterator<ABasicNpc> npcFocusIterator; npcFocusIterator; ++npcFocusIterator) { if (npcFocusIterator->GetWorld() == currentGameWorld) { ABasicNpc* npcChar = *npcFocusIterator; npcChar->hideFocusComponent(); npcChar->removeFocus(); } } }
// check only for enemies which are free to target in the given range bool ACharacterTargetSystem::checkFreeTargetEnemies(ACharacter* player, UWorld* currentGameWorld, float distance) { ABasicEnemy* enemyChar; bool enemyFreeForTarget = false; float distanceToTarget = distance; // TODO for (TObjectIterator<ABasicEnemy> enemyIterator; enemyIterator; ++enemyIterator) { if (enemyIterator->GetWorld() == currentGameWorld) { enemyChar = *enemyIterator; float distanceToPlayer = enemyChar->GetDistanceTo(player); if (!enemyChar->IsPendingKill() && distanceToPlayer < distanceToTarget) { bool isEnemySkipped = enemyChar->bSkippedTarget; if (!isEnemySkipped) { enemyFreeForTarget = true; } } } } return enemyFreeForTarget; }
bool UInputBlueprintLibrary::K2_RebindAxisKey(FValorAxisInputBinding OriginalBinding, FValorAxisInputBinding NewBinding) { UInputSettings* Settings = const_cast<UInputSettings*>(GetDefault<UInputSettings>()); if (!Settings) { return false; } TArray<FInputAxisKeyMapping>& AxisMappings = Settings->AxisMappings; bool bFound = false; for (FInputAxisKeyMapping& AxisKeyMapping : AxisMappings) { if (AxisKeyMapping.AxisName.ToString() == OriginalBinding.AxisName && AxisKeyMapping.Key == OriginalBinding.Key) { UpdateAxisMapping(AxisKeyMapping, NewBinding); bFound = true; break; } } if (bFound) { const_cast<UInputSettings*>(Settings)->SaveKeyMappings(); for (TObjectIterator<UPlayerInput> It; It; ++It) { It->ForceRebuildingKeyMaps(true); } } return bFound; }
void UInputBlueprintLibrary::K2_RemoveAxisKeyBinding(FValorAxisInputBinding BindingToRemove) { UInputSettings* Settings = GetMutableDefault<UInputSettings>(); if (!Settings) { return; } TArray<FInputAxisKeyMapping>& AxisMappings = Settings->AxisMappings; bool bFound = false; for (int32 Index = 0; Index < AxisMappings.Num(); ++Index) { if (AxisMappings[Index].Key == BindingToRemove.Key) { bFound = true; AxisMappings.RemoveAt(Index); Index = 0; } } if (bFound) { Settings->SaveKeyMappings(); for (TObjectIterator<UPlayerInput> It; It; ++It) { It->ForceRebuildingKeyMaps(true); } } }
FGlobalComponentReregisterContext::FGlobalComponentReregisterContext(const TArray<UClass*>& ExcludeComponents) { ActiveGlobalReregisterContextCount++; // wait until resources are released FlushRenderingCommands(); // Detach only actor components that are not in the excluded list for(TObjectIterator<UActorComponent> ComponentIt;ComponentIt;++ComponentIt) { bool bShouldReregister=true; for( int32 Idx=0; Idx < ExcludeComponents.Num(); Idx++ ) { UClass* ExcludeClass = ExcludeComponents[Idx]; if( ExcludeClass && ComponentIt->IsA(ExcludeClass) ) { bShouldReregister = false; break; } } if( bShouldReregister ) { new(ComponentContexts) FComponentReregisterContext(*ComponentIt); } } }
void UAkGameplayStatics::LoadBankByName(const FString& BankName) { FAkAudioDevice * AudioDevice = FAkAudioDevice::Get(); if( AudioDevice ) { if(AudioDevice->GetAkBankManager() != NULL ) { for ( TObjectIterator<UAkAudioBank> Iter; Iter; ++Iter ) { if( Iter->GetName() == BankName ) { Iter->Load(); return; } } // Bank not found in the assets, load it by name anyway AkUInt32 bankID; AudioDevice->LoadBank(BankName, AK_DEFAULT_POOL_ID, bankID); } else { AkUInt32 bankID; AudioDevice->LoadBank(BankName, AK_DEFAULT_POOL_ID, bankID); } } }
void UAkGameplayStatics::UnloadBankByName(const FString& BankName) { FAkAudioDevice * AudioDevice = FAkAudioDevice::Get(); if( AudioDevice ) { if(AudioDevice->GetAkBankManager() != NULL ) { for ( TObjectIterator<UAkAudioBank> Iter; Iter; ++Iter ) { if( Iter->GetName() == BankName ) { Iter->Unload(); return; } } // Bank not found in the assets, unload it by name anyway AudioDevice->UnloadBank(BankName); } else { AudioDevice->UnloadBank(BankName); } } }
void UBillboardComponent::SetEditorScale(float InEditorScale) { EditorScale = InEditorScale; for(TObjectIterator<UBillboardComponent> It; It; ++It) { It->MarkRenderStateDirty(); } }
void UMaterialInterface::RecacheAllMaterialUniformExpressions() { // For each interface, reacache its uniform parameters for( TObjectIterator<UMaterialInterface> MaterialIt; MaterialIt; ++MaterialIt ) { MaterialIt->RecacheUniformExpressions(); } }
void OnObjectReimported(UObject* InObject) { if (UTexture2D* Texture = Cast<UTexture2D>(InObject)) { for (TObjectIterator<UPaperSprite> SpriteIt; SpriteIt; ++SpriteIt) { SpriteIt->OnObjectReimported(Texture); } } }
void UColorPadActivator::DeactivateAllColorPads() { for (TObjectIterator<UColorPadActivator> Itr; Itr; ++Itr) { UColorPadActivator *Trigger = *Itr; Itr->IsActive = false; if (Itr->GetOwner()) { UE_LOG(LogTemp, Warning, TEXT("%s deactivated"), *Itr->GetOwner()->GetName()); } } return; }
void AFPSCharacter::GetMyHealth() { if (GEngine) { TObjectIterator< APlayerController > ThePC; UWorld* TheWorld = ThePC->GetWorld(); AFPSGM* MyGM = Cast<AFPSGM>(UGameplayStatics::GetGameMode(TheWorld)); if (MyGM != NULL) { GEngine->AddOnScreenDebugMessage(1, 5.f, FColor::Red, FString::FromInt(MyGM->Health)); } } }
void NUTUtil::GetUnitTestClassDefList(TArray<UUnitTest*>& OutUnitTestClassDefaults) { for (TObjectIterator<UClass> It; It; ++It) { if (It->IsChildOf(UUnitTest::StaticClass()) && *It != UUnitTest::StaticClass() && *It != UClientUnitTest::StaticClass()) { UUnitTest* CurDefault = Cast<UUnitTest>(It->GetDefaultObject()); if (CurDefault != NULL) { OutUnitTestClassDefaults.Add(CurDefault); } } } }
void AssembleListOfExporters(TArray<UExporter*>& OutExporters) { auto TransientPackage = GetTransientPackage(); // @todo DB: Assemble this set once. OutExporters.Empty(); for (TObjectIterator<UClass> It; It; ++It) { if (It->IsChildOf(UExporter::StaticClass()) && !It->HasAnyClassFlags(CLASS_Abstract)) { UExporter* Exporter = NewObject<UExporter>(TransientPackage, *It); OutExporters.Add(Exporter); } } }
void ACharacterTargetSystem::makeAllNpcsFocusable(UWorld* currentGameWorld) { ABasicNpc* npcChar; for (TObjectIterator<ABasicNpc> npcFreeIterator; npcFreeIterator; ++npcFreeIterator) { if (npcFreeIterator->GetWorld() == currentGameWorld) { npcChar = *npcFreeIterator; if (npcChar) { npcChar->bSkippedTarget = false; } } } }
void ACharacterTargetSystem::makeAllEnemiesFocusable(UWorld* currentGameWorld) { ABasicEnemy* enemyChar; for (TObjectIterator<ABasicEnemy> enemyFreeIterator; enemyFreeIterator; ++enemyFreeIterator) { if (enemyFreeIterator->GetWorld() == currentGameWorld) { enemyChar = *enemyFreeIterator; if (enemyChar && !enemyChar->IsPendingKill()) { enemyChar->bSkippedTarget = false; } } } }
bool ASkill::SphereTrace(AActor* actorToIgnore, const FVector& start, const FVector& end, const float radius, TArray<FHitResult>& hitOut, ECollisionChannel traceChannel /* = ECC_Pawn */) { FCollisionQueryParams traceParams(FName(TEXT("Sphere Trace")), true, actorToIgnore); traceParams.bTraceComplex = true; traceParams.bReturnPhysicalMaterial = false; traceParams.AddIgnoredActor(actorToIgnore); TObjectIterator<APlayerController> pc; if (!pc) return false; DrawDebugSphere(pc->GetWorld(), start, radius, 8, FColor::Red, true); return pc->GetWorld()->SweepMultiByChannel(hitOut, start, end, FQuat(), traceChannel, FCollisionShape::MakeSphere(radius), traceParams); }
void USoundCue::PostEditChangeProperty(struct FPropertyChangedEvent& PropertyChangedEvent) { Super::PostEditChangeProperty(PropertyChangedEvent); if (PropertyChangedEvent.Property) { for (TObjectIterator<UAudioComponent> It; It; ++It) { if (It->Sound == this && It->bIsActive) { It->Stop(); It->Play(); } } } }
void ACharacterTargetSystem::findNPCTargetByDistance(ACharacter* player, UWorld* currentGameWorld, float distance) { ABasicNpc* npcChar; float distanceToPlayer; float distanceToTarget = distance; bool npcFreeForTarget = checkFreeTargetNpcs(currentGameWorld); // if every enemy has been skipped, set all to be focusable again if (!npcFreeForTarget) { makeAllNpcsFocusable(currentGameWorld); } // get distance to enemy that can be focused for (TObjectIterator<ABasicNpc> npcFocusIterator; npcFocusIterator; ++npcFocusIterator) { if (npcFocusIterator->GetWorld() == currentGameWorld) { npcChar = *npcFocusIterator; if (npcChar && player && npcChar->bSkippedTarget == false) { distanceToPlayer = npcChar->GetDistanceTo(player); if (distanceToPlayer < distanceToTarget) { npcChar->bSkippedTarget = true; npcChar->setFocus(); targetedNpc = npcChar; break; } else { npcChar->removeFocus(); targetedNpc = nullptr; } } else { npcChar->removeFocus(); targetedNpc = nullptr; } } } }
void ULevelStreaming::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) { UProperty* OutermostProperty = PropertyChangedEvent.Property; if ( OutermostProperty != NULL ) { const FName PropertyName = OutermostProperty->GetFName(); if (PropertyName == GET_MEMBER_NAME_CHECKED(ULevelStreaming, LevelTransform)) { GetWorld()->UpdateLevelStreaming(); } if (PropertyName == GET_MEMBER_NAME_CHECKED(ULevelStreaming, EditorStreamingVolumes)) { RemoveStreamingVolumeDuplicates(); // Update levels references in each streaming volume for (TActorIterator<ALevelStreamingVolume> It(GetWorld()); It; ++It) { (*It)->UpdateStreamingLevelsRefs(); } } else if (PropertyName == GET_MEMBER_NAME_CHECKED(ULevelStreaming, LevelColor)) { // Make sure the level's Level Color change is applied immediately by reregistering the // components of the actor's in the level if( LoadedLevel != NULL ) { UPackage* Package = LoadedLevel->GetOutermost(); for( TObjectIterator<UActorComponent> It; It; ++It ) { if( It->IsIn( Package ) ) { UActorComponent* ActorComponent = Cast<UActorComponent>( *It ); if( ActorComponent ) { ActorComponent->RecreateRenderState_Concurrent(); } } } } } } Super::PostEditChangeProperty(PropertyChangedEvent); }
void ACharacterTargetSystem::findEnemyTargetByDistance(ACharacter* player, UWorld* currentGameWorld, float distance) { ABasicEnemy* enemyChar; float distanceToPlayer; float distanceToTarget = distance; //TODO CHECK THIS IN DISTANCE bool enemyFreeForTarget = checkFreeTargetEnemies(player, currentGameWorld, distance); // if every enemy has been skipped, set all to be focusable again if (!enemyFreeForTarget) { makeAllEnemiesFocusable(currentGameWorld); } // get distance to enemy that can be focused for (TObjectIterator<ABasicEnemy> enemyFocusIterator; enemyFocusIterator; ++enemyFocusIterator) { if (enemyFocusIterator->GetWorld() == currentGameWorld) { enemyChar = *enemyFocusIterator; if (enemyChar && !enemyChar->IsPendingKill() && player && enemyChar->bSkippedTarget == false) { distanceToPlayer = enemyChar->GetDistanceTo(player); if (distanceToPlayer < distanceToTarget) { enemyChar->bSkippedTarget = true; enemyChar->setFocus(); targetedEnemy = enemyChar; break; } else { enemyChar->removeFocus(); } } else { enemyChar->removeFocus(); targetedEnemy = nullptr; } } } }
/** * Loads all of the code packages completely (for script classes). Then iterates * through the UClass-es finding all commandlets and dumping information on them */ static void ListAllCommandlets(void) { warnf(TEXT("%-40s %s"),TEXT("Commandlet"),TEXT("Description")); warnf(TEXT("--------------------------------------------------------------------------------")); // Now iterate through all UClass-es looking for commandlets for (TObjectIterator<UClass> It; It; ++It) { UCommandlet* DefObject = Cast<UCommandlet>(It->GetDefaultObject()); if (DefObject != NULL) { // Ignore commandlets that can't be created if (It->HasAnyClassFlags(CLASS_Abstract) == FALSE) { const FString& Name = GetCommandletName(DefObject); warnf(TEXT("%-40s - %s"),*Name,*DefObject->HelpDescription); } } } }
bool ACharacterTargetSystem::checkFreeTargetNpcs(UWorld* currentGameWorld) { ABasicNpc* npcChar; bool npcFreeForTarget = false; // check if every enemy has been focused yet for (TObjectIterator<ABasicNpc> npcIterator; npcIterator; ++npcIterator) { if (npcIterator->GetWorld() == currentGameWorld) { npcChar = *npcIterator; bool isEnemySkipped = npcChar->bSkippedTarget; if (!isEnemySkipped) { npcFreeForTarget = true; } } } return npcFreeForTarget; }
void ReattachMaterials(const TArray<FString>& Args) { FMaterialUpdateContext MaterialUpdateContext; UE_LOG(LogConsoleResponse, Display, TEXT("Reattach.Materials:")); // Clear the parents out of combination material for( TObjectIterator<UMaterial> MaterialIt; MaterialIt; ++MaterialIt ) { if(Args.Num() == 1) { UE_LOG(LogConsoleResponse, Display, TEXT(" %s"), *MaterialIt->GetName()); if(MaterialIt->GetName() == Args[0]) { MaterialUpdateContext.AddMaterial(*MaterialIt); } } } UE_LOG(LogConsoleResponse, Display, TEXT("")); }
/** * Initializes the list of possible level streaming methods. * Does nothing if the lists are already initialized. */ void InitializeStreamingMethods() { check( GStreamingMethodStrings.Num() == GStreamingMethodClassList.Num() ); if ( GStreamingMethodClassList.Num() == 0 ) { // Assemble a list of possible level streaming methods. for ( TObjectIterator<UClass> It ; It ; ++It ) { if ( It->IsChildOf( ULevelStreaming::StaticClass() ) && (It->HasAnyClassFlags(CLASS_EditInlineNew)) && !(It->HasAnyClassFlags(CLASS_Hidden | CLASS_Abstract | CLASS_Deprecated | CLASS_Transient))) { const FString ClassName( It->GetName() ); // Strip the leading "LevelStreaming" text from the class name. // @todo DB: This assumes the names of all ULevelStreaming-derived types begin with the string "LevelStreaming". GStreamingMethodStrings.Add( ClassName.Mid( 14 ) ); GStreamingMethodClassList.Add( *It ); } } } }
void UAdvancedSessionsLibrary::GetNumberOfNetworkPlayers(int32 &NumNetPlayers) { //Get an actor to GetWorld() from TObjectIterator<AActor> Itr; if (!Itr) { UE_LOG(AdvancedSessionsLog, Warning, TEXT("GetNumberOfNetworkPlayers Failed to get iterator!")); return; } //~~~~~~~~~~~~ //Get World UWorld* TheWorld = Itr->GetWorld(); if (!TheWorld) { UE_LOG(AdvancedSessionsLog, Warning, TEXT("GetNumberOfNetworkPlayers Failed to get World()!")); return; } TArray<class APlayerState*>& PlayerArray = (TheWorld->GetGameState()->PlayerArray); NumNetPlayers = PlayerArray.Num(); }
void UBehaviorTreeManager::DumpUsageStats() const { FNodeClassCounter AllNodesCounter; for (TObjectIterator<UClass> It; It; ++It) { if (It->IsChildOf(UBTNode::StaticClass()) && It->HasAnyClassFlags(CLASS_Abstract) == false #if WITH_EDITOR && !(FKismetEditorUtilities::IsClassABlueprintSkeleton(*It) || It->HasAnyClassFlags(CLASS_NewerVersionExists)) #endif ) { AllNodesCounter.Declare(*It); } } UE_LOG(LogBehaviorTree, Display, TEXT("----------------------UBehaviorTreeManager::DumpUsageStats----------------------\nBehavior Trees:")); // get all BTNode classes for (TObjectIterator<UBehaviorTree> It; It; ++It) { FNodeClassCounter TreeNodeCounter; UE_LOG(LogBehaviorTree, Display, TEXT("--- %s ---"), *(It->GetName())); StatNodeUsage(It->RootNode, TreeNodeCounter); TreeNodeCounter.Print(); AllNodesCounter.Append(TreeNodeCounter); } UE_LOG(LogBehaviorTree, Display, TEXT("--- Total Nodes usage:")); AllNodesCounter.Print(TEXT(",")); }
// Called when the game starts or when spawned void AEnemyManager_2::BeginPlay() { Super::BeginPlay(); for (TObjectIterator<AVikingMinion> Itr; Itr; ++Itr) { if (Itr->ActorHasTag("VikingMinion")) { //minions_list.Add(reinterpret_cast<AVikingMinion*>(Itr->GetActorClass())); //minions_list.Add(Itr); } } //UE_LOG(LogTemp, Warning, TEXT("enemy manager called, number is %d"), minion_count); //minions_list.Shrink(); //minion_count = minions_list.Max(); }
bool UDiffAssetsCommandlet::LoadFile(const FString& Filename, TArray<UObject *>& LoadedObjects) { UPackage* Package = Cast<UPackage>(LoadPackage( NULL, *Filename, LOAD_None )); if (!Package) { UE_LOG(LogDiffAssetsCommandlet, Warning, TEXT("Could not load %s"), *Filename); return false; } for (TObjectIterator<UObject> It; It; ++It) { if (It->GetOuter() == Package) { LoadedObjects.Add(*It); } } if (!LoadedObjects.Num()) { UE_LOG(LogDiffAssetsCommandlet, Warning, TEXT("Loaded %s, but it didn't contain any objects."), *Filename); return false; } LoadedObjects.Sort(); return true; }
void UExporter::ExportObjectInner(const FExportObjectInnerContext* Context, UObject* Object, FOutputDevice& Ar, uint32 PortFlags, bool bSkipComponents) { // indent all the text in here TextIndent += 3; FExportObjectInnerContext::InnerList ObjectInners; if ( Context ) { const FExportObjectInnerContext::InnerList* Inners = Context->ObjectToInnerMap.Find( Object ); if ( Inners ) { ObjectInners = *Inners; } } else { for (TObjectIterator<UObject> It; It; ++It) { if ( It->GetOuter() == Object ) { ObjectInners.Add( *It ); } } } TArray<UObject*> Components; if (!bSkipComponents) { // first export the components Object->CollectDefaultSubobjects(Components, false); } if (!(PortFlags & PPF_SeparateDefine)) { for ( int32 ObjIndex = 0 ; ObjIndex < ObjectInners.Num() ; ++ObjIndex ) { // NOTE: We ignore inner objects that have been tagged for death UObject* Obj = ObjectInners[ObjIndex]; if ( !Obj->IsPendingKill() && !Obj->IsDefaultSubobject() && !Obj->HasAnyFlags(RF_TextExportTransient) && FCString::Stricmp(*Obj->GetClass()->GetName(), TEXT("Model")) != 0) { // export the object UExporter::ExportToOutputDevice( Context, Obj, NULL, Ar, (PortFlags & PPF_Copy) ? TEXT("Copy") : TEXT("T3D"), TextIndent, PortFlags | PPF_SeparateDeclare, false, ExportRootScope ); } } if (!bSkipComponents) { ExportComponentDefinitions(Context, Components, Ar, PortFlags | PPF_SeparateDeclare); } } if (!(PortFlags & PPF_SeparateDeclare)) { for ( int32 ObjIndex = 0 ; ObjIndex < ObjectInners.Num() ; ++ObjIndex ) { // NOTE: We ignore inner objects that have been tagged for death UObject* Obj = ObjectInners[ObjIndex]; if ( !Obj->IsPendingKill() && !Obj->IsDefaultSubobject() && !Obj->HasAnyFlags(RF_TextExportTransient) && FCString::Stricmp(*Obj->GetClass()->GetName(), TEXT("Model")) != 0) { // export the object UExporter::ExportToOutputDevice( Context, Obj, NULL, Ar, (PortFlags & PPF_Copy) ? TEXT("Copy") : TEXT("T3D"), TextIndent, PortFlags | PPF_SeparateDefine, false, ExportRootScope ); // don't reexport below in ExportProperties Obj->Mark(OBJECTMARK_TagImp); } } if (!bSkipComponents) { ExportComponentDefinitions(Context, Components, Ar, PortFlags | PPF_SeparateDefine); } // export the object's properties // Note: we use archetype as the object to diff properties against before they exported. When object is created, they should create from archetype // and using this system, it should recover all properties it needs to copy uint8 *CompareObject; if (Object->HasAnyFlags(RF_ClassDefaultObject)) { CompareObject = (uint8*)Object; } else { CompareObject = (uint8*)Object->GetArchetype(); } ExportProperties( Context, Ar, Object->GetClass(), (uint8*)Object, TextIndent, Object->GetClass(), CompareObject, Object, PortFlags, ExportRootScope ); if (!bSkipComponents) { // Export anything extra for the components. Used for instanced foliage. // This is done after the actor properties so these are set when regenerating the extra data objects. ExportComponentExtra( Context, Components, Ar, PortFlags ); } } // remove indent TextIndent -= 3; }