Cast to different actor than BTs actor

Hello. I have 2 different NPCs with their own Behaviour trees. First NPC called Victim has variable called State which is boolean and is set to be False by default. In certain point i set this variable to True. Second NPC called Bystander has its own Behaviour tree that is depended on State variable of first NPC. when i set it to True nothing happens in Bystanders Behaviour tree. I dont know what im doing wrong because when i start game nothing happens and it stays on CheckState_B node and doesnt move forward.

Hi, the cast will only work if the controlled pawn that is running CheckState_B is of type Victim. Otherwise it will fail.

So you could either

(-) use “GetActorOfClass” if there is only ever going to be one Victim and use that instead of casting

(-) set a reference to the victim you want in the blackboard and use that

If you use GetActorOfClass Victim, then there is no need to cast it to Victim, it is already of type Victim.

the Bystander Behaviour tree wont
react to it even if i use
GetActorOfClass.

Did you again use GetActorOfClass Victim when you try to access a variable?


You could do some prints in your logic and also use the AI debugger (to watch the behavior tree variables) to see where it is not doing what you would expect it to.

There will be only one instance of Victim NPC but it still doesnt work. After I use GetActorOfClass to change State variable to True, the Bystander Behaviour tree wont react to it.
It doesnt work if State varable is either editable or not editable.

Ive never used AI debugger but i will try it and see how it works. The thing i am trying to do is that Victims behaviour tree have to change variable of Victim and then Bystanders behaviour tree has blueprint that is checking the change of variable and has to react to it. I will try debugging and comment again