void UCarlaSettingsDelegate::SetAllActorsDrawDistance(UWorld* world, const float max_draw_distance) const { ///@TODO: use semantics to grab all actors by type (vehicles,ground,people,props) and set different distances configured in the global properties if(!world||!IsValid(world)||world->IsPendingKill()) return; AsyncTask(ENamedThreads::GameThread, [=](){ if(!world||!IsValid(world)||world->IsPendingKill()) return; TArray<AActor*> actors; #define _MAX_SCALE_SIZE 50.0f //set the lower quality - max draw distance UGameplayStatics::GetAllActorsOfClass(world, AActor::StaticClass(),actors); for(int32 i=0; i<actors.Num(); i++) { AActor* actor = actors[i]; if(!IsValid(actor) || actor->IsPendingKill() || actor->IsA<AInstancedFoliageActor>() || //foliage culling is controlled per instance actor->IsA<ALandscape>() || //dont touch landscapes nor roads actor->ActorHasTag(UCarlaSettings::CARLA_ROAD_TAG) || actor->ActorHasTag(UCarlaSettings::CARLA_SKY_TAG) ){ continue; } SetActorComponentsDrawDistance(actor, max_draw_distance); } }); }
PyObject *py_ue_actor_has_tag(ue_PyUObject * self, PyObject * args) { ue_py_check(self); char *tag; if (!PyArg_ParseTuple(args, "s:actor_has_tag", &tag)) { return NULL; } if (!self->ue_object->IsA<AActor>()) { return PyErr_Format(PyExc_Exception, "uobject is not an AActor"); } AActor *actor = (AActor *)self->ue_object; if (actor->ActorHasTag(FName(UTF8_TO_TCHAR(tag)))) { Py_INCREF(Py_True); return Py_True; } Py_INCREF(Py_False); return Py_False; }
// Called when the game starts or when spawned void ATeleportLR::BeginPlay() { Super::BeginPlay(); //Find player for (TActorIterator<AActor> It(GetWorld()); It; ++It) { AActor* Actor = *It; if (Actor->ActorHasTag(FName(TEXT("player")))) { player = (AUfo*)Actor; } } }
void AAgent::CheckLoS() { AAgentController* Controller = Cast<AAgentController>(GetController()); if (Controller != NULL) { // Get the location of the agent FVector AgentLocation = GetActorLocation(); // Get the direction the agent is facing FVector Direction = GetActorForwardVector(); // Default trace params FCollisionQueryParams TraceParams(TEXT("LineOfSight_Trace"), false, this); TraceParams.bTraceAsyncScene = true; //=====Draw line trace from agent to player=====// FHitResult Hit(ForceInit); UWorld* World = GetWorld(); World->LineTraceSingleByChannel(Hit, AgentLocation + Direction, Controller->GetFocalPoint(), ECollisionChannel::ECC_Visibility, TraceParams, FCollisionResponseParams::DefaultResponseParam); //DrawDebugLine(World, AgentLocation + Direction, Controller->GetFocalPoint(), FColor::Yellow, false, -1, 0, 2.0f); //==============================================// AActor* HitActor = Hit.GetActor(); if (HitActor != NULL && HitActor->ActorHasTag("Player")) { } /* Otherwise we can assume the actor intersecting the line trace is blocking the line of sight from the agent to the player */ else if (HitActor != NULL) { /* The focal point is currently on the player actor. Set the PlayerLocation blackboard key to the location of this focal point, so that when the agent moves into the Search behaviour it will move to the actual location of the player when the agent lost LoS as opposed to the last location it sensed the player at. */ Controller->SetPlayerLocation(Controller->GetFocalPoint()); // LoS to player is blocked bPlayerSeen = false; // Reset the player has seen blackboard key so that the Agent can begin searching. Controller->SetPlayerFound(bPlayerSeen); // Clear the focus on the player Controller->ClearFocus(EAIFocusPriority::Gameplay); bCanSearch = true; Controller->SetCanSearch(bCanSearch); // Stop firing if still firing if (isFiring) StopFiring(); } } }
// Called when the game starts or when spawned void AEnemy::BeginPlay() { Super::BeginPlay(); //Set Random Material int randMat = FMath::RandRange(0, enemyMaterials.Num() - 1); StaticMesh->SetMaterial(0, enemyMaterials[randMat]); //Get reference to gamestate gameState = GetWorld() != NULL ? GetWorld()->GetGameState<APacGameState>() : NULL; //Find player for (TActorIterator<AActor> It(GetWorld()); It; ++It) { AActor* Actor = *It; if (Actor->ActorHasTag(FName(TEXT("player")))) { player = (AUfo*)Actor; } } ufoVelocity = FVector(0.0f, 1.0f, 0.0f)*velMultiplier; GetForward(); }