1 Ai Work perfect But 2 Ai Work garbage

1 Ai Work perfect But 2 Ai Work garbage

whats im doing wrong :
my guess is all Ai use same behavior tree but they have own BlackBoards , in behavior tree, I use a lot of Custom decorators, services and tasks and they have own values ( static values in .h files ) since all AI use same behavior tree the static values get set for all AI to use that behavior tree an this is the problem .

it’s really weird to me if all AI uses the same behavior tree please tell me if I got it correct or wrong.

if I do not get it correct pleas tell me whats I do wrong.

Note: all “Instance Synced” is false.

Thanks…

AI doesn’t use the same behaviour tree. The statics you have in your header, are being used for ALL AI. You don’t want to use statics.

Please read up on statics Static Keyword in C++ - GeeksforGeeks

Statics are not per instance, but are per class. Meaning ALL your AI use the same values those statics are set too.

Thanks for replay, I delete all static values but the results are the same, The only way it works correctly is I duplicate my Behavior tree and give each AI different behavior tree!

for example in header of one of my Tasks :

#include "CoreMinimal.h"
#include "BehaviorTree/BTTaskNode.h"
#include "AfterHidIsFightTask.generated.h"

/**
 * 
 */
UCLASS()
class SHOOTEMUP_API UAfterHidIsFightTask : public UBTTaskNode
{
	GENERATED_BODY()

		UAfterHidIsFightTask();

	virtual EBTNodeResult::Type ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory)override;

	virtual void TickTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory, float DeltaSeconds)override;

	class UBlackboardComponent * BlackBoardComp;

	class AEnemyPawn* OwnerShip;

	AActor * FirstPlayerActor;

	USkeletalMeshComponent * ShipBase;

	bool DoOnce = true;

	int32 TotalHealth;

	int32 MaxRand = 5000;
	
};

it seems two int32 TotalHealth and bool DoOnce = true; values are shared with all AI’s for example if first AI makes DoOnce = false for all Ai its gets false! I don’t know what I don’t understand here if you have info about it please explaining it to me im really confuse.

thanks again for replay.

Ah you need to set the task as instanced.
Place:
bCreateNodeInstance = true;

in your constructor of your task.

Really thanks dude its fix my problem, it was really big help, I search in few books, online training nowhere mention this! really thanks.