x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

[4.11] C++ Behaviour tree not running

Hi guys,

I'm working with a behavior tree in UE4 4.10 (C++ and Blueprint) and my behavior tree was working fine but since I switch to 4.11 my behavior tree isn't doing anything. At least the first Blueprint Service not showing any print to Screen in the event "Receive Tick AI". Maybe I've done something wrong, but I don't find what is it.

Here my following code:

Controller.cpp

 #include "Invaders.h"
 #include "InvadersBuildingsAIController.h"
 
 AInvadersBuildingsAIController::AInvadersBuildingsAIController()
     : AAIController()
 {
     static ConstructorHelpers::FObjectFinder<UBlackboardData> bb(TEXT("BlackboardData'/Game/Buildings/BB_Building.BB_Building'"));
     static ConstructorHelpers::FObjectFinder<UBehaviorTree> bt(TEXT("BehaviorTree'/Game/Buildings/BT_Building.BT_Building'"));
     Blackboard = CreateDefaultSubobject<UBlackboardComponent>("Blackboard");
     blackboardData = bb.Object;
     behaviorTree = bt.Object;
 }
 
 void AInvadersBuildingsAIController::BeginPlay()
 {
     Initialize();
 }
 
 void AInvadersBuildingsAIController::Initialize()
 {
     if (!Blackboard->InitializeBlackboard(*blackboardData))
     {
         GEngine->AddOnScreenDebugMessage(-1, 1, FColor::Red, "Could not load Blackboard");
         return;
     }
     Blackboard->SetValueAsFloat("AttackCooldown", 0.0f);
 
     AInvadersActor* npc = Cast<AInvadersActor>(GetPawn());
     if (npc)
     {
         Blackboard->SetValueAsObject("SelfActor", GetPawn());
         if (!RunBehaviorTree(behaviorTree))
             GEngine->AddOnScreenDebugMessage(-1, 1, FColor::Red, "Could not run behavior");
         else
             GEngine->AddOnScreenDebugMessage(-1, 1, FColor::Green, "Run Behavior Tree");
     }
 }




Controller.h

 #pragma once
 
 #include "Invaders Base/InvadersActor.h"
 #include "AIController.h"
 #include "Runtime/AIModule/Classes/BehaviorTree/BlackboardComponent.h"
 #include "Runtime/AIModule/Classes/BehaviorTree/BehaviorTree.h"
 #include "InvadersBuildingsAIController.generated.h"
 
 UCLASS()
 class INVADERS_API AInvadersBuildingsAIController : public AAIController
 {
     GENERATED_BODY()
 
 public:
     AInvadersBuildingsAIController();
 
     virtual void BeginPlay() override;
 
     void Initialize();
 
     UPROPERTY(EditAnywhere, Category = "Invaders AI")
         UBlackboardData* blackboardData;
 
     UPROPERTY(EditAnywhere, Category = "Invaders AI")
         UBehaviorTree* behaviorTree;
 };


Behavior Tree : BT_Building

alt text

Blueprint Service : BTServ_FindEnnemies

alt text

In the Controller.cpp, the function "RunBehaviorTree(behaviorTree)" is working and it prints the debug message "Run Behavior Tree" like it should be. Right after the event Receive Tick AI, I try to print "Hello" but it's not showing anything and consequently the rest of the blueprint and the behavior tree not working.

If someone knows what happens, I will gladly hear it.

Thanks for the future answers.

Product Version: UE 4.11
Tags:
more ▼

asked Apr 19 '16 at 10:03 AM in C++ Programming

avatar image

Gatekeeper
1 1 2 2

avatar image Gatekeeper May 01 '16 at 12:30 PM

Hi guys,

I still have this problem and don't know why. Any idea of what is the problem?

Thanks

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Hey there - having the same issue. BehaviourTree working fine in 4.10, does not work at all in 4.11.

 if (AICharacter && AICharacter->AIBehavior && AICharacter->AIBehavior->BlackboardAsset)
 {
     BlackboardComponent->InitializeBlackboard(*AICharacter->AIBehavior->BlackboardAsset);
     
     BlackboardProperties.TargetKeyID = BlackboardComponent->GetKeyID("Target");
     BlackboardProperties.LastSensedLocationID = BlackboardComponent->GetKeyID("LastSensedLocation");
     BlackboardProperties.NextWeaponID = BlackboardComponent->GetKeyID("NextWeapon");
     BlackboardProperties.NextWeaponLocationID = BlackboardComponent->GetKeyID("NextWeaponLocation");

     BlackboardProperties.ShouldProcessCommandsID = BlackboardComponent->GetKeyID("ShouldProcessCommands");
     BlackboardProperties.CommandTypeID = BlackboardComponent->GetKeyID("CommandType");
     BlackboardProperties.CommandActorID = BlackboardComponent->GetKeyID("CommandActor");
     BlackboardProperties.CommandLocationID = BlackboardComponent->GetKeyID("CommandLocation");

     BehaviourComponent->StartTree(*AICharacter->AIBehavior);
 }
more ▼

answered May 22 '16 at 03:10 AM

avatar image

RyroNZ
61 1 2 4

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question