baehun92
(baehun92)
March 29, 2016, 10:07am
1
HI I wanted change Behavior Tree in Runtime.
RunBehaviorTree Function return true but not work Behavior Tree.
this is my code.
void AMonsterBaseController::Possess( APawn* InPawn ) {
Super::Possess( InPawn );
Owner = Cast<AMonsterBase>( InPawn );
if ( !Owner ) {
UE_LOG( LogClass, Log, TEXT( "MonsterBaseController Get Onwer Null" ) );
}
if ( Owner->GetStateByBehaviorTree( AMonsterBase::EBaseState::Chase )->BlackboardAsset ) {
Blackboard->InitializeBlackboard( *Owner->GetStateByBehaviorTree( AMonsterBase::EBaseState::Chase )->BlackboardAsset );
bool rtVal = RunBehaviorTree( Owner->GetStateByBehaviorTree( AMonsterBase::EBaseState::Chase ) );
if ( !rtVal )
GEngine->AddOnScreenDebugMessage( -1, 10, FColor::Blue, TEXT( "Behavior Tree Not Run" ) );
}
}
What should I do
rantrod
(rantrod)
March 30, 2016, 5:56am
2
Try calling StopTree on your UBehaviorTreeComponent before calling RunBehaviorTree and see if that helps.
UBehaviorTreeComponent* BTComp = Cast<UBehaviorTreeComponent>(BrainComponent);
if(BTComp) BTComp->StopTree();
bool rtVal = RunBehaviorTree( Owner->GetStateByBehaviorTree( AMonsterBase::EBaseState::Chase ) );
…
baehun92
(baehun92)
March 30, 2016, 2:57pm
3
Oh It is Work
Than you.
but It work Only In Tick Function
Not Work in Possess Function
Can I know why not work in Possess Function?
rantrod
(rantrod)
March 30, 2016, 5:14pm
4
You don’t need the call to InitializeBlackboard, it gets automatically called from RunBehaviorTree, but you do need the StopTree before it…
I don’t see other errors in the code you provided. Perhaps the error is elsewhere?
baehun92
(baehun92)
March 31, 2016, 2:07am
5
Do not see any errors.
Debug That Code
But Work Well
I am not Use Possess Function and Project well making
thank you