本文整理汇总了C++中UBehaviorTreeComponent类的典型用法代码示例。如果您正苦于以下问题:C++ UBehaviorTreeComponent类的具体用法?C++ UBehaviorTreeComponent怎么用?C++ UBehaviorTreeComponent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UBehaviorTreeComponent类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: ExecuteTask
EBTNodeResult::Type UMyBTTask_ResetRoute::ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory)
{
/* Check whether the AIController component exists to avoid errors */
ABotAI* MyController = Cast<ABotAI>(OwnerComp.GetAIOwner());
if (MyController == nullptr)
{
return EBTNodeResult::Failed;
}
//uint8 BBResetRoute = OwnerComp.GetBlackboardComponent()->GetKeyID("ResetRoute");
//uint8 BBResetRoute = OwnerComp.GetBlackboardComponent()->GetKeyID("ResetRoute");
uint8 BBResetRoute = OwnerComp.GetBlackboardComponent()->GetKeyID("ResetRoute");
OwnerComp.GetBlackboardComponent()->SetValueAsBool(BBResetRoute, true);
// uint8 BBResetRoute = OwnerComp.GetBlackboardComponent()->GetKeyID("ResetRoute");
return EBTNodeResult::Succeeded;
}
开发者ID:jackdurnford,项目名称:MidnightSnag,代码行数:27,代码来源:MyBTTask_ResetRoute.cpp
示例2: FindNodeOwner
bool FindNodeOwner(AActor* OwningActor, class UBTNode* Node, UBehaviorTreeComponent*& OwningComp, int32& OwningInstanceIdx)
{
bool bFound = false;
APawn* OwningPawn = Cast<APawn>(OwningActor);
if (OwningPawn && OwningPawn->Controller)
{
bFound = FindNodeOwner(OwningPawn->Controller, Node, OwningComp, OwningInstanceIdx);
}
if (OwningActor && !bFound)
{
TArray<UBehaviorTreeComponent*> Components;
OwningActor->GetComponents(Components);
for (int32 ComponentIndex = 0; ComponentIndex < Components.Num(); ComponentIndex++)
{
UBehaviorTreeComponent* BTComp = Components[ComponentIndex];
if (BTComp)
{
const int32 InstanceIdx = BTComp->FindInstanceContainingNode(Node);
if (InstanceIdx != INDEX_NONE)
{
OwningComp = BTComp;
OwningInstanceIdx = InstanceIdx;
bFound = true;
break;
}
}
}
}
return bFound;
}
开发者ID:1vanK,项目名称:AHRUnrealEngine,代码行数:33,代码来源:BlueprintNodeHelpers.cpp
示例3: ExecuteTask
EBTNodeResult::Type UEngageTask::ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory)
{
UBehaviorTreeComponent* BTComp = &OwnerComp;
const UBlackboardComponent* BlackboardComp = BTComp->GetBlackboardComponent();
AAgentController* Controller = Cast<AAgentController>(BTComp->GetAIOwner());
if (Controller == NULL)
{
return EBTNodeResult::Failed;
}
else
{
class AAgent* Agent = Controller->GetAgentOwner();
// If the agent's weapon has ammo in it
if (Agent->GetCurrentWeapon()->CalculateAmmo() > 0)
{
// Ensure reload is set to false because it should have been reloaded at this stage
Agent->EndReload();
// Shoot
Agent->Fire();
}
else
{
// Stop firing if firing
Agent->StopFiring();
// Reload
Agent->BeginReload();
}
return EBTNodeResult::Succeeded;
}
return EBTNodeResult::Failed;
}
开发者ID:ChristopherMurray194,项目名称:Final_Project,代码行数:33,代码来源:EngageTask.cpp
示例4: IsTaskExecuting
bool UBTTask_BlueprintBase::IsTaskExecuting() const
{
UBehaviorTreeComponent* OwnerComp = Cast<UBehaviorTreeComponent>(GetOuter());
EBTTaskStatus::Type TaskStatus = OwnerComp->GetTaskStatus(this);
return (TaskStatus == EBTTaskStatus::Active);
}
开发者ID:colwalder,项目名称:unrealengine,代码行数:7,代码来源:BTTask_BlueprintBase.cpp
示例5: ExecuteTask
EBTNodeResult::Type UBTTask_MoveToPlayer::ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory)
{
AEnemyAI *CharPC = Cast<AEnemyAI>(OwnerComp.GetAIOwner());
ASacredHeartCharacter *Enemy = Cast<ASacredHeartCharacter>(OwnerComp.GetBlackboardComponent()->GetValue<UBlackboardKeyType_Object>(CharPC->EnemyKeyID));
if (Enemy)
{
int bpm = Enemy->heartRate;
if (bpm > 100)
{
CharPC->GetCharacter()->GetCharacterMovement()->MaxWalkSpeed = 550;
CharPC->MoveToActor(Enemy, 5.f, true, true, true, 0, true);
return EBTNodeResult::Succeeded;
}
else
{
return EBTNodeResult::Failed;
}
}
else
{
return EBTNodeResult::Failed;
}
}
开发者ID:Hydroxate,项目名称:SacredHeart,代码行数:28,代码来源:BTTask_MoveToPlayer.cpp
示例6: ExecuteTask
EBTNodeResult::Type UMyBTTask_FindWayPoint::ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory)
{
/* Check whether the AIController component exists to avoid errors */
ABotAI* MyController = Cast<ABotAI>(OwnerComp.GetAIOwner());
if (MyController == nullptr)
{
return EBTNodeResult::Failed;
}
/* Gets pointer to a waypoint */
AEnemyWayPoint* CurrentWaypoint = MyController->GetWaypoint();
AActor* NewWaypoint = nullptr;
/* Get all Actors of type "EnemyWayPoint" in the level, and Iterate through them */
TArray<AActor*> AllWaypoints;
UGameplayStatics::GetAllActorsOfClass(MyController, AEnemyWayPoint::StaticClass(), AllWaypoints);
/* Select one random waypoint by index */
NewWaypoint = AllWaypoints[FMath::RandRange(0, AllWaypoints.Num() - 1)];
if (NewWaypoint)
{
/* Assign the retrieved waypoint to blackboard as the new move destination */
OwnerComp.GetBlackboardComponent()->SetValue<UBlackboardKeyType_Object>(BlackboardKey.GetSelectedKeyID(), NewWaypoint);
return EBTNodeResult::Succeeded;
}
return EBTNodeResult::Failed;
}
开发者ID:jackdurnford,项目名称:MidnightSnag,代码行数:32,代码来源:MyBTTask_FindWayPoint.cpp
示例7: CalculateRawConditionValue
bool UBTDecorator_IsAtLocation::CalculateRawConditionValue(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory) const
{
bool bHasReached = false;
AAIController* AIOwner = OwnerComp.GetAIOwner();
UPathFollowingComponent* PathFollowingComponent = AIOwner ? AIOwner->GetPathFollowingComponent() : nullptr;
if (PathFollowingComponent)
{
const UBlackboardComponent* MyBlackboard = OwnerComp.GetBlackboardComponent();
if (BlackboardKey.SelectedKeyType == UBlackboardKeyType_Object::StaticClass())
{
UObject* KeyValue = MyBlackboard->GetValue<UBlackboardKeyType_Object>(BlackboardKey.GetSelectedKeyID());
AActor* TargetActor = Cast<AActor>(KeyValue);
if (TargetActor)
{
bHasReached = PathFollowingComponent->HasReached(*TargetActor, AcceptableRadius, false, bUseNavAgentGoalLocation);
}
}
else if (BlackboardKey.SelectedKeyType == UBlackboardKeyType_Vector::StaticClass())
{
const FVector TargetLocation = MyBlackboard->GetValue<UBlackboardKeyType_Vector>(BlackboardKey.GetSelectedKeyID());
if (FAISystem::IsValidLocation(TargetLocation))
{
bHasReached = PathFollowingComponent->HasReached(TargetLocation, AcceptableRadius);
}
}
}
return bHasReached;
}
开发者ID:amyvmiwei,项目名称:UnrealEngine4,代码行数:31,代码来源:BTDecorator_IsAtLocation.cpp
示例8: OnCeaseRelevant
void UBTService_BlueprintBase::OnCeaseRelevant(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory)
{
Super::OnCeaseRelevant(OwnerComp, NodeMemory);
if (!OwnerComp.HasAnyFlags(RF_BeginDestroyed) && OwnerComp.GetOwner())
{
// force dropping all pending latent actions associated with this blueprint
// we can't have those resuming activity when node is/was aborted
BlueprintNodeHelpers::AbortLatentActions(OwnerComp, *this);
if (AIOwner != nullptr && ReceiveActivationImplementations & FBTNodeBPImplementationHelper::AISpecific)
{
ReceiveDeactivationAI(AIOwner, AIOwner->GetPawn());
}
else if (ReceiveActivationImplementations & FBTNodeBPImplementationHelper::Generic)
{
ReceiveDeactivation(ActorOwner);
}
}
else
{
UE_LOG(LogBehaviorTree, Warning,
TEXT("OnCeaseRelevant called on Blueprint service %s with invalid owner. OwnerComponent: %s, OwnerComponent Owner: %s. %s")
, *GetNameSafe(this), *OwnerComp.GetName(), *GetNameSafe(OwnerComp.GetOwner())
, OwnerComp.HasAnyFlags(RF_BeginDestroyed) ? TEXT("OwnerComponent has BeginDestroyed flag") : TEXT("")
);
}
}
开发者ID:Foreven,项目名称:Unreal4-1,代码行数:28,代码来源:BTService_BlueprintBase.cpp
示例9: ExecuteTask
EBTNodeResult::Type UChooseNextWaypoint::ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory)
{
// Get the patrol route
auto ControlledPawn = OwnerComp.GetAIOwner()->GetPawn();
auto PatrolRoute = ControlledPawn->FindComponentByClass<UPatrolRoute>();
if (!ensure(PatrolRoute)) { return EBTNodeResult::Failed; }
// Warn about empty patrol routes
auto PatrolPoints = PatrolRoute->GetPatrolPoints();
if (PatrolPoints.Num() == 0)
{
UE_LOG(LogTemp, Warning, TEXT("A guard is missing patrol points."));
return EBTNodeResult::Failed;
}
// Set the next waypoint
auto BlackboardComp = OwnerComp.GetBlackboardComponent();
auto Index = BlackboardComp->GetValueAsInt(IndexKey.SelectedKeyName);
BlackboardComp->SetValueAsObject(WaypointKey.SelectedKeyName, PatrolPoints[Index]);
// Cycle the index
auto NextIndex = (Index + 1) % PatrolPoints.Num();
BlackboardComp->SetValueAsInt(IndexKey.SelectedKeyName, NextIndex);
// UE_LOG(LogTemp, Warning, TEXT("Waypoint index: %i"), Index);
return EBTNodeResult::Succeeded;
}
开发者ID:spire8989,项目名称:TestingGrounds,代码行数:28,代码来源:ChooseNextWaypoint.cpp
示例10: SetFinishOnMessageWithId
void UBTTask_BlueprintBase::SetFinishOnMessageWithId(FName MessageName, int32 RequestID)
{
UBehaviorTreeComponent* OwnerComp = Cast<UBehaviorTreeComponent>(GetOuter());
if (OwnerComp)
{
OwnerComp->RegisterMessageObserver(this, MessageName, RequestID);
}
}
开发者ID:colwalder,项目名称:unrealengine,代码行数:8,代码来源:BTTask_BlueprintBase.cpp
示例11: OnBlackboardChange
void UBTDecorator_BlueprintBase::OnBlackboardChange(const UBlackboardComponent& Blackboard, FBlackboard::FKey ChangedKeyID)
{
UBehaviorTreeComponent* BehaviorComp = (UBehaviorTreeComponent*)Blackboard.GetBrainComponent();
if (BehaviorComp && GetShouldAbort(*BehaviorComp))
{
BehaviorComp->RequestExecution(this);
}
}
开发者ID:Foreven,项目名称:Unreal4-1,代码行数:8,代码来源:BTDecorator_BlueprintBase.cpp
示例12: OnBlackboardChange
void UBTDecorator_CompareBBEntries::OnBlackboardChange(const UBlackboardComponent& Blackboard, FBlackboard::FKey ChangedKeyID)
{
UBehaviorTreeComponent* BehaviorComp = static_cast<UBehaviorTreeComponent*>(Blackboard.GetBrainComponent());
if (BehaviorComp && (BlackboardKeyA.GetSelectedKeyID() == ChangedKeyID || BlackboardKeyB.GetSelectedKeyID() == ChangedKeyID))
{
BehaviorComp->RequestExecution(this);
}
}
开发者ID:Foreven,项目名称:Unreal4-1,代码行数:8,代码来源:BTDecorator_CompareBBEntries.cpp
示例13: TickNode
void UBMAgroCheck::TickNode(UBehaviorTreeComponent&OwnerComp, uint8* NodeMemory, float DeltaSeconds)
{
Super::TickNode(OwnerComp, NodeMemory, DeltaSeconds);
if (ThisTree == nullptr || ThisController == nullptr || ThisAICharacter == nullptr)
{
ThisTree = OwnerComp.GetCurrentTree();
ThisController = Cast<ABMAIController>(OwnerComp.GetAIOwner());
ThisAICharacter = Cast<ABMBossCharacter>(ThisController->GetPawn());
if (ThisTree == nullptr || ThisController == nullptr || ThisAICharacter == nullptr)
{
UE_LOG(LogTemp, Warning, TEXT("Warning Agro Service performed on invalid AI"));
return;
}
}
// Initialize a sweep params struct with trace complex set to true
FCollisionQueryParams SphereSweepParams(FName(TEXT("AgroCheckSweep")), true, ThisAICharacter);
FCollisionObjectQueryParams ObjectQuery(ECC_GameTraceChannel1);
// Initialize Hit Result
FHitResult HitOut(ForceInit);
DrawDebugSphere(ThisAICharacter->GetWorld(), ThisAICharacter->GetActorLocation(), 1500, 12, FColor::Red, false, 4.0f);
// Perform the sweep and check boolean return, we will only be checking for BMCharacter objects
bool bResult = ThisAICharacter->GetWorld()->SweepSingleByObjectType(HitOut,
ThisAICharacter->GetActorLocation(),
ThisAICharacter->GetActorLocation() + FVector(0.0f, 0.0f, 10.0f),
FQuat(),
ObjectQuery,
FCollisionShape::MakeSphere(1500),
SphereSweepParams);
if (bResult)
{
ThisController->GetBlackboard()->SetValueAsObject(TEXT("TargetToFollow"), HitOut.GetActor());
ThisController->GetBlackboard()->SetValueAsVector(TEXT("HomeLocation"), ThisAICharacter->GetActorLocation());
ThisController->GetBlackboard()->SetValueAsVector(TEXT("TargetLocation"), HitOut.GetActor()->GetActorLocation());
ThisController->TrackToTarget();
}
else
{
ThisController->GetBlackboard()->SetValueAsObject(TEXT("TargetToFollow"), nullptr);
ThisController->StopTrack();
}
}
开发者ID:PacktPublishing,项目名称:Unreal-Engine-4X-By-Example,代码行数:56,代码来源:BMAgroCheck.cpp
示例14: ensure
//----------------------------------------------------------------------//
// UBTTaskNode IGameplayTaskOwnerInterface
//----------------------------------------------------------------------//
void UBTTaskNode::OnTaskDeactivated(UGameplayTask& Task)
{
ensure(Task.GetTaskOwner() == this);
UBehaviorTreeComponent* BTComp = GetBTComponentForTask(Task);
if (BTComp)
{
// this is a super-default behavior. Specific task will surely like to
// handle this themselves, finishing with specific result
const EBTTaskStatus::Type Status = BTComp->GetTaskStatus(this);
FinishLatentTask(*BTComp, Status == EBTTaskStatus::Aborting ? EBTNodeResult::Aborted : EBTNodeResult::Succeeded);
}
}
开发者ID:dineshone,项目名称:UnrealGameEngine,代码行数:15,代码来源:BTTaskNode.cpp
示例15: DescribeInstance
FString FBehaviorTreeDebugger::DescribeInstance(UBehaviorTreeComponent& InstanceToDescribe) const
{
FString ActorDesc;
if (InstanceToDescribe.GetOwner())
{
AController* TestController = Cast<AController>(InstanceToDescribe.GetOwner());
ActorDesc = TestController ?
TestController->GetName() :
InstanceToDescribe.GetOwner()->GetActorLabel();
}
return ActorDesc;
}
开发者ID:Codermay,项目名称:Unreal4,代码行数:13,代码来源:BehaviorTreeDebugger.cpp
示例16: ExecuteTask
EBTNodeResult::Type UBTTaskNode_ChooseNextSpell::ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory)
{
Super::ExecuteTask(OwnerComp, NodeMemory);
auto controller = Cast<ABaseAIController>(OwnerComp.GetAIOwner());
auto blackboard = OwnerComp.GetBlackboardComponent();
auto spellData = controller->GetNextSpell();
blackboard->SetValueAsObject("NextSpell", spellData);
return EBTNodeResult::Type::Succeeded;
}
开发者ID:metsfan,项目名称:thirdpersonproject,代码行数:13,代码来源:BTTask_ChooseNextSpell.cpp
示例17: HasCooldownFinished
bool UBTDecorator_TagCooldown::HasCooldownFinished(const UBehaviorTreeComponent& OwnerComp) const
{
const float TagCooldownEndTime = OwnerComp.GetTagCooldownEndTime(CooldownTag);
if (TagCooldownEndTime == 0.f)
{
// special case, we don't have an end time yet for this cooldown tag
return true;
}
const float TimePassed = (OwnerComp.GetWorld()->GetTimeSeconds() - TagCooldownEndTime);
return TimePassed >= CooldownDuration;
}
开发者ID:Foreven,项目名称:Unreal4-1,代码行数:14,代码来源:BTDecorator_TagCooldown.cpp
示例18: NotifyChildExecution
void UBTComposite_SimpleParallel::NotifyChildExecution(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory, int32 ChildIdx, EBTNodeResult::Type& NodeResult) const
{
FBTParallelMemory* MyMemory = (FBTParallelMemory*)NodeMemory;
if (ChildIdx == EBTParallelChild::MainTask)
{
MyMemory->MainTaskResult = NodeResult;
if (NodeResult == EBTNodeResult::InProgress)
{
EBTTaskStatus::Type Status = OwnerComp.GetTaskStatus(Children[EBTParallelChild::MainTask].ChildTask);
if (Status == EBTTaskStatus::Active)
{
// can't register if task is currently being aborted (latent abort returns in progress)
MyMemory->bMainTaskIsActive = true;
MyMemory->bForceBackgroundTree = false;
OwnerComp.RegisterParallelTask(Children[EBTParallelChild::MainTask].ChildTask);
RequestDelayedExecution(OwnerComp, EBTNodeResult::Succeeded);
}
}
else if (MyMemory->bMainTaskIsActive)
{
MyMemory->bMainTaskIsActive = false;
const int32 MyInstanceIdx = OwnerComp.FindInstanceContainingNode(this);
OwnerComp.UnregisterParallelTask(Children[EBTParallelChild::MainTask].ChildTask, MyInstanceIdx);
if (NodeResult != EBTNodeResult::Aborted && !MyMemory->bRepeatMainTask)
{
// check if subtree should be aborted when task finished with success/failed result
if (FinishMode == EBTParallelMode::AbortBackground)
{
OwnerComp.RequestExecution((UBTCompositeNode*)this, MyInstanceIdx,
Children[EBTParallelChild::MainTask].ChildTask, EBTParallelChild::MainTask,
NodeResult);
}
}
}
else if (NodeResult == EBTNodeResult::Succeeded && FinishMode == EBTParallelMode::WaitForBackground)
{
// special case: if main task finished instantly, but composite is supposed to wait for background tree,
// request single run of background tree anyway
MyMemory->bForceBackgroundTree = true;
RequestDelayedExecution(OwnerComp, EBTNodeResult::Succeeded);
}
}
}
开发者ID:RandomDeveloperM,项目名称:UE4_Hairworks,代码行数:50,代码来源:BTComposite_SimpleParallel.cpp
示例19: InitializeInSubtree
void UBTNode::InitializeInSubtree(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory, int32& NextInstancedIndex, EBTMemoryInit::Type InitType) const
{
if (bCreateNodeInstance)
{
// composite nodes can't be instanced!
check(IsA(UBTCompositeNode::StaticClass()) == false);
UBTNode* NodeInstance = OwnerComp.NodeInstances.IsValidIndex(NextInstancedIndex) ? OwnerComp.NodeInstances[NextInstancedIndex] : NULL;
if (NodeInstance == NULL)
{
NodeInstance = NewObject<UBTNode>(&OwnerComp, GetClass(), GetFName(), RF_NoFlags, (UObject*)(this));
NodeInstance->InitializeNode(GetParentNode(), GetExecutionIndex(), GetMemoryOffset(), GetTreeDepth());
NodeInstance->bIsInstanced = true;
OwnerComp.NodeInstances.Add(NodeInstance);
}
check(NodeInstance);
NodeInstance->SetOwner(OwnerComp.GetOwner());
FBTInstancedNodeMemory* MyMemory = GetSpecialNodeMemory<FBTInstancedNodeMemory>(NodeMemory);
MyMemory->NodeIdx = NextInstancedIndex;
NodeInstance->OnInstanceCreated(OwnerComp);
NextInstancedIndex++;
}
else
{
InitializeMemory(OwnerComp, NodeMemory, InitType);
}
}
开发者ID:didixp,项目名称:Ark-Dev-Kit,代码行数:31,代码来源:BTNode.cpp
示例20: ExecuteTask
EBTNodeResult::Type USetMaxWalkSpeed::ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory)
{
Super::ExecuteTask(OwnerComp, NodeMemory);
if (!GetWorld())
{
return EBTNodeResult::Failed;
}
AActor* AnnaActor = OwnerComp.GetBlackboardComponent()->GetOwner();
if (AnnaActor)
{
ACharacter* AnnaCharacter = Cast<AController>(AnnaActor)->GetCharacter();
if (AnnaCharacter)
{
AnnaCharacter->GetCharacterMovement()->MaxWalkSpeed = DesiredMaxSpeed;
EBTNodeResult::Succeeded;
}
}
return EBTNodeResult::Failed;
}
开发者ID:Snowman5717,项目名称:SymphonyOfShadows,代码行数:25,代码来源:SetMaxWalkSpeed.cpp
注:本文中的UBehaviorTreeComponent类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论