Setup NPC director
This commit is contained in:
@@ -2,6 +2,9 @@
|
||||
|
||||
|
||||
#include "NPC.h"
|
||||
#include "NPCTypeDefinition.h"
|
||||
#include "NPCAIController.h"
|
||||
#include "Components/SkeletalMeshComponent.h"
|
||||
#include "GameFramework/CharacterMovementComponent.h"
|
||||
|
||||
ANPC::ANPC()
|
||||
@@ -13,5 +16,67 @@ ANPC::ANPC()
|
||||
GetCharacterMovement()->bOrientRotationToMovement = false;
|
||||
bUseControllerRotationYaw = false;
|
||||
AutoPossessAI = EAutoPossessAI::PlacedInWorldOrSpawned;
|
||||
|
||||
// Crowd anim hygiene (mesh-agnostic): only evaluate the pose while the NPC is on screen and
|
||||
// throttle the eval rate by distance. CharacterMovement still ticks off-screen so pooled-in
|
||||
// NPCs can keep walking; only the visible pose freezes when unrendered.
|
||||
if (USkeletalMeshComponent* MeshComp = GetMesh())
|
||||
{
|
||||
MeshComp->VisibilityBasedAnimTickOption = EVisibilityBasedAnimTickOption::OnlyTickPoseWhenRendered;
|
||||
MeshComp->bEnableUpdateRateOptimizations = true;
|
||||
}
|
||||
}
|
||||
|
||||
ENPCType ANPC::GetNPCType() const
|
||||
{
|
||||
return NPCTypeDefinition ? NPCTypeDefinition->Type : ENPCType::Walker;
|
||||
}
|
||||
|
||||
float ANPC::GetObservationWeight() const
|
||||
{
|
||||
return NPCTypeDefinition ? NPCTypeDefinition->ObservationWeight : 1.0f;
|
||||
}
|
||||
|
||||
bool ANPC::ShouldStopToObserve() const
|
||||
{
|
||||
return NPCTypeDefinition ? NPCTypeDefinition->bStopsToObserve : false;
|
||||
}
|
||||
|
||||
float ANPC::GetObserveDuration() const
|
||||
{
|
||||
return NPCTypeDefinition ? NPCTypeDefinition->ObserveDurationSeconds : 0.0f;
|
||||
}
|
||||
|
||||
void ANPC::ActivateFromPool(const FVector& Location, const FRotator& Rotation)
|
||||
{
|
||||
SetActorLocationAndRotation(Location, Rotation, false, nullptr, ETeleportType::TeleportPhysics);
|
||||
SetActorHiddenInGame(false);
|
||||
SetActorEnableCollision(true);
|
||||
|
||||
if (UCharacterMovementComponent* Move = GetCharacterMovement())
|
||||
{
|
||||
Move->SetComponentTickEnabled(true);
|
||||
Move->SetMovementMode(MOVE_Walking);
|
||||
}
|
||||
|
||||
OnActivatedFromPool();
|
||||
}
|
||||
|
||||
void ANPC::DeactivateToPool()
|
||||
{
|
||||
// Drop any active observation so a pooled-out NPC stops contributing to the player's embarrassment.
|
||||
if (ANPCAIController* NPCController = Cast<ANPCAIController>(GetController()))
|
||||
NPCController->ClearObservation();
|
||||
|
||||
if (UCharacterMovementComponent* Move = GetCharacterMovement())
|
||||
{
|
||||
Move->StopMovementImmediately();
|
||||
Move->DisableMovement();
|
||||
Move->SetComponentTickEnabled(false);
|
||||
}
|
||||
|
||||
SetActorHiddenInGame(true);
|
||||
SetActorEnableCollision(false);
|
||||
|
||||
OnDeactivatedToPool();
|
||||
}
|
||||
Reference in New Issue
Block a user