void UAStarAgentComponent::BeginPlay() { Super::BeginPlay(); for (TActorIterator<AAStarGrid> Itr(GetWorld()); Itr; ++Itr) m_grid = *Itr; for (TActorIterator<AAStarPathfinderActor> Itr(GetWorld()); Itr; ++Itr) m_pathfinder = *Itr; if (!m_pathfinder) UE_LOG(LogTemp, Warning, TEXT("ERROR: could not find pathfinder, AStarAgentComponent")); if (!m_grid) UE_LOG(LogTemp, Warning, TEXT("ERROR: could not find grid, AStarAgentComponent")); }
void ArchiveManager::LoadSkippedArchives(const char* ArchiveDirectory) { if (*LoadedArchives == 0) return; for (IDirectoryIterator Itr(ArchiveDirectory, "*.bsa"); !Itr.Done(); Itr.Next()) { std::string FileName(Itr.Get()->cFileName); FileName = FileName.substr(FileName.rfind("\\") + 1); bool IsLoaded = false; for (ArchiveListT::Iterator Itr = (*LoadedArchives)->Begin(); !Itr.End() && Itr.Get(); ++Itr) { std::string LoadedFileName(Itr.Get()->fileName); LoadedFileName = LoadedFileName.substr(LoadedFileName.rfind("\\") + 1); if (!_stricmp(LoadedFileName.c_str(), FileName.c_str())) { IsLoaded = true; break; } } if (IsLoaded == false) { LoadArchive(FileName.c_str(), 0, 0); BGSEECONSOLE_MESSAGE("Loaded %s", FileName.c_str()); } } }
PyObject *py_ue_find_actor_by_label(ue_PyUObject * self, PyObject * args) { ue_py_check(self); char *name; if (!PyArg_ParseTuple(args, "s:find_actor_by_label", &name)) { return NULL; } UWorld *world = ue_get_uworld(self); if (!world) return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject"); UObject *u_object = nullptr; for (TActorIterator<AActor> Itr(world); Itr; ++Itr) { AActor *u_obj = *Itr; if (u_obj->GetActorLabel().Equals(UTF8_TO_TCHAR(name))) { u_object = u_obj; break; } } if (u_object) { ue_PyUObject *ret = ue_get_python_wrapper(u_object); if (!ret) return PyErr_Format(PyExc_Exception, "PyUObject is in invalid state"); Py_INCREF(ret); return (PyObject *)ret; } Py_INCREF(Py_None); return Py_None; }
UInt32 ActorAnimationOverrider::GetSpecialAnims( TESNPC* NPC, const char* Tag, AnimationFileListT& OutFiles ) const { SME_ASSERT(NPC && Tag); std::string SkeletonPath = (NPC->model.nifPath.m_data ? NPC->model.nifPath.m_data : ""); int Count = 0; if (SkeletonPath.size()) { SkeletonPath.erase(SkeletonPath.rfind("\\")); OutFiles.clear(); std::string SourceDir = "Data\\Meshes\\" + SkeletonPath + "\\SpecialAnims\\";; std::string SearchFilter = "*" + kOverrideFileTag + std::string(Tag) + ".kf"; for (IDirectoryIterator Itr(SourceDir.c_str(), SearchFilter.c_str()); Itr.Done() == false; Itr.Next()) { #ifndef NDEBUG // _MESSAGE("Override Found - %s", Itr.Get()->cFileName); #endif // !NDEBUG OutFiles.push_back(Itr.Get()->cFileName); Count++; } } return Count; }
PyObject *py_ue_find_actor_by_label(ue_PyUObject * self, PyObject * args) { ue_py_check(self); char *name; if (!PyArg_ParseTuple(args, "s:find_actor_by_label", &name)) { return NULL; } UWorld *world = ue_get_uworld(self); if (!world) return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject"); UObject *u_object = nullptr; for (TActorIterator<AActor> Itr(world); Itr; ++Itr) { AActor *u_obj = *Itr; if (u_obj->GetActorLabel().Equals(UTF8_TO_TCHAR(name))) { u_object = u_obj; break; } } if (u_object) { Py_RETURN_UOBJECT(u_object); } Py_RETURN_NONE; }
// Called when the game starts or when spawned void AViewManager::BeginPlay() { Super::BeginPlay(); TopViewAnchor = this->GetWorld()->SpawnActor(AActor::StaticClass()); //TopViewAnchorRootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("Top View Anchor Root Component")); TopViewAnchorRootComponent = NewObject<USceneComponent>(TopViewAnchor, TEXT("Root Component")); TopViewAnchor->SetRootComponent(TopViewAnchorRootComponent); for (TActorIterator<AVantagePoint> Itr(GetWorld()) ; Itr; ++Itr) { Itr->ViewManagerParent = this; VantagePoints.Add(*Itr); } if (VantagePoints.Num() > 0) { TargetVantagePoint = VantagePoints[0]; } else { //error - no vantage points in the scene } TurnOffOutlineRendering(); }
void ANinjaGameModeBase::ClearPlayerStartTags() { UWorld* World = GetWorld(); if (World) { for (TActorIterator<APlayerStart> Itr(World); Itr; ++Itr) { APlayerStart* Actor = *Itr; if (Actor) { Actor->PlayerStartTag = FName(TEXT("Free")); } } } }
// When initialized, this component will check if a RealSenseSessionManager actor // exists in the scene. If the actor exists, this component stores a reference to // it. If it does not, a new RealSenseSessionManager actor will be spawned, and a // reference to it will be saved. void URealSenseComponent::InitializeComponent() { if (globalRealSenseSession == nullptr) { for (TActorIterator<ARealSenseSessionManager> Itr(GetWorld()); Itr; ++Itr) { globalRealSenseSession = (ARealSenseSessionManager*)*Itr; } if (globalRealSenseSession == nullptr) { RS_LOG(Log, "Creating RealSenseSessionManager Actor") globalRealSenseSession = GetWorld()->SpawnActor<ARealSenseSessionManager>(ARealSenseSessionManager::StaticClass()); } } }
AActor * ANinjaGameModeBase::ChoosePlayerStart_Implementation(AController * Player) { UWorld* World = GetWorld(); if (World) { for (TActorIterator<APlayerStart> Itr(World); Itr; ++Itr) { APlayerStart* Actor = *Itr; if (Actor) { if (Actor->PlayerStartTag.IsEqual(FName(TEXT("None")))) { //GEngine->AddOnScreenDebugMessage(-1, 1.5, FColor::Red, TEXT("Tag is None")); return Super::ChoosePlayerStart_Implementation(Player); } if (!(Actor->PlayerStartTag.IsEqual(FName("Taken")))) { //GEngine->AddOnScreenDebugMessage(-1, 1.5, FColor::Red, TEXT("PS is not taken")); return Actor; } } } } return nullptr; }
void FObjectReplicator::PostReceivedBunch() { // Call PostNetReceive const bool bIsServer = (OwningChannel->Connection->Driver->ServerConnection == NULL); if (!bIsServer && bHasReplicatedProperties) { PostNetReceive(); bHasReplicatedProperties = false; } // Check if PostNetReceive() destroyed Object UObject *Object = GetObject(); if (Object == NULL || Object->IsPendingKill()) { return; } RepLayout->CallRepNotifies( RepState, Object ); // Call RepNotifies if ( RepNotifies.Num() > 0 ) { for (int32 RepNotifyIdx = 0; RepNotifyIdx < RepNotifies.Num(); RepNotifyIdx++) { //UE_LOG(LogNet, Log, TEXT("Calling Object->%s with %s"), *RepNotifies(RepNotifyIdx)->RepNotifyFunc.ToString(), *RepNotifies(RepNotifyIdx)->GetName()); UProperty* RepProperty = RepNotifies[RepNotifyIdx]; UFunction* RepNotifyFunc = Object->FindFunctionChecked(RepProperty->RepNotifyFunc); if (RepNotifyFunc->NumParms == 0) { Object->ProcessEvent(RepNotifyFunc, NULL); } else if (RepNotifyFunc->NumParms == 1) { Object->ProcessEvent(RepNotifyFunc, RepProperty->ContainerPtrToValuePtr<uint8>(RepState->StaticBuffer.GetTypedData()) ); } else if (RepNotifyFunc->NumParms == 2) { // Fixme: this isn't as safe as it could be. Right now we have two types of parameters: MetaData (a TArray<uint8>) // and the last local value (pointer into the Recent[] array). // // Arrays always expect MetaData. Everything else, including structs, expect last value. // This is enforced with UHT only. If a ::NetSerialize function ever starts producing a MetaData array thats not in UArrayProperty, // we have no static way of catching this and the replication system could pass the wrong thing into ProcessEvent here. // // But this is all sort of an edge case feature anyways, so its not worth tearing things up too much over. FMemMark Mark(FMemStack::Get()); uint8* Parms = new(FMemStack::Get(),MEM_Zeroed,RepNotifyFunc->ParmsSize)uint8; TFieldIterator<UProperty> Itr(RepNotifyFunc); check(Itr); Itr->CopyCompleteValue( Itr->ContainerPtrToValuePtr<void>(Parms), RepProperty->ContainerPtrToValuePtr<uint8>(RepState->StaticBuffer.GetTypedData()) ); ++Itr; check(Itr); TArray<uint8> *NotifyMetaData = RepNotifyMetaData.Find(RepNotifies[RepNotifyIdx]); check(NotifyMetaData); Itr->CopyCompleteValue( Itr->ContainerPtrToValuePtr<void>(Parms), NotifyMetaData ); Object->ProcessEvent(RepNotifyFunc, Parms ); Mark.Pop(); } if (Object == NULL || Object->IsPendingKill()) { // script event destroyed Object break; } } } RepNotifies.Reset(); RepNotifyMetaData.Empty(); }
void AOrionRandomWaveSpawner::SpawnWave(int32 TypesToSpawn[SPAWN_NUM], AActor *Focus) { if (Role != ROLE_Authority) return; if (GetWorld() == nullptr || GetWorld()->GetNavigationSystem() == nullptr) return; AOrionGRI *GRI = Cast<AOrionGRI>(GetWorld()->GameState); if (GRI && GRI->bSideMission) FocusActor = this; else FocusActor = Focus; //FailedToSpawn.Empty(); AOrionGameMode *Game = Cast<AOrionGameMode>(GetWorld()->GetAuthGameMode()); for (int32 i = 0; i < SPAWN_NUM; i++) { ////if (!ClassEnabled[i]) //// continue; //possible error checking ////TypesToSpawn[i] = FMath::Min(15, TypesToSpawn[i]); for (int32 j = 0; j < TypesToSpawn[i]; j++) { FActorSpawnParameters SpawnInfo; SpawnInfo.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AdjustIfPossibleButDontSpawnIfColliding; FVector Loc; FVector vStart = GetWorld()->GetNavigationSystem()->ProjectPointToNavigation(GetWorld(), GetActorLocation(), (ANavigationData *)0, DefaultFilterClass, FVector(100.0f, 100.0f, 100.0f)); Loc = GetWorld()->GetNavigationSystem()->GetRandomPointInNavigableRadius/*GetRandomReachablePointInRadius*/(GetWorld(), vStart, 5000.0f/*SpawnRadius*/, (ANavigationData*)0, DefaultFilterClass); //quick trace to make sure we will be spawning on landscape, don't want dinos spawning on static meshes FCollisionQueryParams TraceParams("DinoHelper", false); TraceParams.bTraceAsyncScene = false; TraceParams.bReturnPhysicalMaterial = false; FHitResult Hit(ForceInit); if (GetWorld()) { GetWorld()->LineTraceSingleByChannel(Hit, Loc + FVector(0.0f, 0.0f, 15.0f), Loc - FVector(0.0f, 0.0f, 200.0f), COLLISION_WEAPON, TraceParams); if (GetWorld()->SweepSingleByChannel(Hit, Loc + FVector(0.0f, 0.0f, 15.0f), Loc - FVector(0.0f, 0.0f, 200.0f), FQuat::Identity, ECollisionChannel::ECC_Pawn, FCollisionShape::MakeSphere(5), TraceParams)) { if (!Cast<ALandscape>(Hit.GetActor())) { Game->SpawnTypes[i]++; continue; } } else { Game->SpawnTypes[i]++; continue; } } FSharedConstNavQueryFilter QueryFilter = UNavigationQueryFilter::GetQueryFilter(GetWorld()->GetNavigationSystem()->MainNavData, DefaultFilterClass); if (!GetWorld()->GetNavigationSystem()->TestPathSync(FPathFindingQuery(nullptr, *GetWorld()->GetNavigationSystem()->MainNavData, vStart, Loc, QueryFilter))) { Game->SpawnTypes[i]++; continue; } bool bExit = false; for (TActorIterator<AOrionPlayerController> Itr(GetWorld()); Itr && !bExit; ++Itr) { AOrionPlayerController *PC = *Itr; AOrionCharacter *P = Cast<AOrionCharacter>(PC->GetPawn()); if (P == nullptr) continue; if ((P->GetActorLocation() - Loc).SizeSquared() < 2250000.0) bExit = true; } if (bExit) { //FailedToSpawn.Add(i); Game->SpawnTypes[i]++; continue; } AOrionCharacter* NewPawn = GetWorld()->SpawnActor<AOrionCharacter>(SpawnClasses[i], Loc + FVector(0, 0, 1.05f) * SpawnClasses[i].GetDefaultObject()->GetCapsuleComponent()->GetScaledCapsuleHalfHeight(), GetActorRotation(), SpawnInfo); if (NewPawn) { if (Game) Game->AddActiveWaveEnemy(NewPawn); NewPawn->bRun = true; //NewPawn->FocusArea = FocusLocation; NewPawn->FocusActor = FocusActor; NewPawn->SpawnDefaultController(); NewPawn->SetAIType(AI_HUNTING); NewPawn->SpawnType = i; //setup the enemies level for ilvl stuff NewPawn->Level = Game->GetEnemyItemLevel(true); //setup health based on ilvl NewPawn->HealthMax = NewPawn->HealthMax * FMath::Pow(LEVELPOWER, NewPawn->Level / LEVELINTERVAL) * 0.1f; NewPawn->Health = NewPawn->HealthMax; //same for shields (robots only) NewPawn->ShieldMax = NewPawn->ShieldMax * FMath::Pow(LEVELPOWER, NewPawn->Level / LEVELINTERVAL) * 0.1f; NewPawn->Shield = NewPawn->ShieldMax; } else if (Game) { //FailedToSpawn.Add(i); Game->SpawnTypes[i]++; continue; } } } /*if (FailedToSpawn.Num() > 0) { GetWorldTimerManager().SetTimer(FailedTimer, this, &AOrionRandomWaveSpawner::SpawnFailures, 1.0f, false); }*/ }
void AHUD::GetActorsInSelectionRectangle(TSubclassOf<class AActor> ClassFilter, const FVector2D& FirstPoint, const FVector2D& SecondPoint, TArray<AActor*>& OutActors, bool bIncludeNonCollidingComponents, bool bActorMustBeFullyEnclosed) { // Because this is a HUD function it is likely to get called each tick, // so make sure any previous contents of the out actor array have been cleared! OutActors.Reset(); //Create Selection Rectangle from Points FBox2D SelectionRectangle(0); //This method ensures that an appropriate rectangle is generated, // no matter what the coordinates of first and second point actually are. SelectionRectangle += FirstPoint; SelectionRectangle += SecondPoint; //The Actor Bounds Point Mapping const FVector BoundsPointMapping[8] = { FVector(1, 1, 1), FVector(1, 1, -1), FVector(1, -1, 1), FVector(1, -1, -1), FVector(-1, 1, 1), FVector(-1, 1, -1), FVector(-1, -1, 1), FVector(-1, -1, -1) }; //~~~ //For Each Actor of the Class Filter Type for (TActorIterator<AActor> Itr(GetWorld(), ClassFilter); Itr; ++Itr) { AActor* EachActor = *Itr; //Get Actor Bounds //casting to base class, checked by template in the .h const FBox EachActorBounds = Cast<AActor>(EachActor)->GetComponentsBoundingBox(bIncludeNonCollidingComponents); /* All Components? */ //Center const FVector BoxCenter = EachActorBounds.GetCenter(); //Extents const FVector BoxExtents = EachActorBounds.GetExtent(); // Build 2D bounding box of actor in screen space FBox2D ActorBox2D(0); for (uint8 BoundsPointItr = 0; BoundsPointItr < 8; BoundsPointItr++) { // Project vert into screen space. const FVector ProjectedWorldLocation = Project(BoxCenter + (BoundsPointMapping[BoundsPointItr] * BoxExtents)); // Add to 2D bounding box ActorBox2D += FVector2D(ProjectedWorldLocation.X, ProjectedWorldLocation.Y); } //Selection Box must fully enclose the Projected Actor Bounds if (bActorMustBeFullyEnclosed) { if(SelectionRectangle.IsInside(ActorBox2D)) { OutActors.Add(Cast<AActor>(EachActor)); } } //Partial Intersection with Projected Actor Bounds else { if (SelectionRectangle.Intersect(ActorBox2D)) { OutActors.Add(Cast<AActor>(EachActor)); } } } }