Download

Behavior Tree Documentation In Progress

I’m working on official behavior tree documentation right now! There’s a lot to say, and I want to make sure it’s clear and definitive, so I can’t promise a date when it will be ready, but it’s coming as soon as possible!

Since there are now so many threads asking questions about behavior tree documentation, I thought I’d answer some of the questions in a single common place and post updates on progress as I’m able.

First of all, note that Behavior Trees are still officially an “Experimental” feature. What that basically means is that we’re still developing them heavily… i.e. changes may be frequent and significant, including new features, etc. For that reason, they’re “off” by default and you have to turn them on if you want to use them.

As for the purpose of this thread: I’m going to start by linking to some of the threads and AnswerHub questions that have significant information about Behavior Trees (both blueprint questions AND C++ questions). I might also re-post some information here, and I’ll update this thread again as soon as any official documentation is available.

Thanks!
Daniel Broder
Senior Gameplay Programmer
Epic Games

1 Like

Awesome man. Thanks!

So, where do we start?

You could also do a twitch showing some stuff for us :slight_smile:

Some threads with relevant posts from various Unreal Developers:

Behavior Tree Tutorial Post, with some Epic developer explanations about differences between UE4 Behavior Trees and standard trees. Also explains how to enable behavior trees, how to create Blackboard assets, and how to create Blueprint behavior tree nodes.
How do you determine which Key on a Blackboard you are accessing. Includes Blueprint & C++ solution.
UE4 Pathfinding basic AI. Includes an example behavior tree for implementing random wandering, and shows an example of how to make a Blueprint Task node.

Some AnswerHUB Posts:
(Some of these are fairly peripheral to the Behavior Tree issue, but they’re still good AI information generally)
How to spawn the correct AI Controller when spawning an AI Pawn
Best method for calling animations from Behavior Trees

LOL, When I posted this thread I intended to immediately follow up with some information (in addition to the links I just finally added), only to get pulled away to some other work for several hours! :frowning:

Hopefully I’ll be able to add some more information tomorrow (while continuing work on the official documentation).

FYI – I will still be reading other threads and responding to them, so don’t feel that you need to come to this thread with questions! I scan through the forums and also search for topics related to my work daily. :slight_smile:

:cool::cool::cool: + 100000000000000000000000000000000000000 :slight_smile:

You guys are freaking awesome. I seem to be one of the people messing with BehaviorTrees at the moment :smiley:
I’ve run into another issue. Either my Keys are not setting, I’m not referencing my Blackboard properly, or something else is wrong here. I can’t tell because DebugMessageToScreen is printing “0” from anywhere in the ReceiveTick function…and it only prints once so it doesn’t seem to be looping or ticking the print function properly. Makes it hard to debug this.

I’m trying to set a Blackboard Key from inside a class extending from BTService_BlueprintBase. Compiles fine, but Key doesn’t set. Hard to debug due to issue printing.

Thanks,

Behavior Tree
27a85c05c368441fa7a9d1bcb23ee95c078f45d4.jpeg

Blackboard Key
d5d9e69a7aed51d92635ee551b4a6ab88e302cb3.jpeg

in BTService_FindAndDetectPlayer.cpp



void UBTService_FindAndDetectPlayer::ReceiveTick(AActor * OwnerActor, float DeltaSeconds)
{
	AActor * PtrToAnActor = NULL;
	UBehaviorTreeComponent* MyComp = Super::CurrentCallOwner;
	if (MyComp == NULL)
	{
		return;
	}

	for (TObjectIterator<AActor> Itr; Itr; ++Itr)
	{
		//any coditions on choosing which actor, such as name or other things;

		if (Itr->GetName()=="PlayerDetTest")
		{
			//Assign your created Ptr to actual Actor in game world
			PtrToAnActor = *Itr;
			GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, "AM I WORKING?");  //WHY IS THIS PRINTING "0". Same result with TEXT("whatever")??
			MyComp->GetBlackboardComponent()->SetValueAsObject(PointKey.SelectedKeyID, PtrToAnActor); //PointKey is set in the BehaviorTree to Player...I have TargetPoint named "PlayerDetTest" in level.
			return;
		}

	}

	//no actor found, return
	if (!PtrToAnActor) return;
}


in .h



UCLASS()
class UBTService_FindAndDetectPlayer : public UBTService_BlueprintBase
{
	GENERATED_UCLASS_BODY()

	virtual void ReceiveTick(AActor * OwnerActor, float DeltaSeconds) OVERRIDE;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Blackboard)
	FBlackboardKeySelector PointKey;
};


@alg0801
One thing I have found is the Key settings on the detail to the right in the Behavior Tree Editor unset themselves, and they all start set as the first key in the list. So, for each node in the BT Graph I need to check them that the key is set correctly in the right panel. That was one thing that hung me up, the reset sometimes when making changes in the tree.

Also, in a BP Service, you need to make the key variable Editable, I don’t know if there is any carry over to the C++ service.

It showed up in editor after I set these parameters:


UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Blackboard)
	FBlackboardKeySelector PointKey;


MyComp->GetBlackboardComponent()->SetValueAsObject(PointKey.SelectedKeyID, PtrToAnActor);

If DebugMessage wasn’t printing “0” I could possibly debug it a bit better. There are many options that could be going wrong.

PtrToAnActor may never find my “DetPlayerTest” named object. Could be a blackboard issue in the way I am setting the key. Really unsure. Since it is printing “0” only one time from anywhere in the function I am unsure if the entire ReceiveTick function is even running. It appears to be inside the BT though…but that should make it print “0” over and over again until I stop.

alg0801, I replied to your questions about your code on your original thread.

Any update on the forthcoming documentation?

Yes, documentation is now being posted in first-pass form to the forums. More polish will be added soon and eventually I hope to make some nice tutorial videos (but that’s a bit farther off still).

Go to this thread for more information on behavior tree docs. I’m declaring this thread dead. ;p