Behavior Trees

I have a question: how would I use my Flashlight Trace and Blueprint interface to work with this tutorial I found so that when I turn on my flashlight and point it at the enemy, the zombie runs off? I have all of it set up except for getting the zombie to react and unreact to the trace and blueprint interface. I was wanting something similar to the Volatiles in Dying Light. even if I don’t use the interface to do it.

I Followed this tutorial
Zombie AI in 11 MINUTES | Unreal Engine 5

Here is the trace information It relies off a branch telling it that the flashlight is on to be able to do the trace and the interface to call it


look like youi’re checking if hit actor = zombie before you set the zombie variable. Since you’re using an interface, you don’t really need to save a hard ref to zombie as a var unless you’ve got some other code using it. Checking if hit actor uses interface kind of unnecessary too, since only an actor withe the interface implemented on it will respond either way, I’d suggest trying send interface message “Run From light” to hit actor immediately after the first branch off blocking hit. Then if you need to save a ref to zombie in your char for some other reason, change the interface event into a function that returns self as an actor from the zombie’s implementation. Would need to add an output pin on the function in the blueprint interface tho.

You should make the decision in the behavior tree. The rough outline should look like this:

  1. Do exactly what you do but the interface functions should probably be something like enterLight and exitLight.
  2. Then in the zombie should immediately get its controller and the running blackboard and set a bool value in the blackboard isLighted or something similar.
  3. In the behavior thee you should make a selector that sets the desired behavior based on the blackboard bool: If lighted - Run, otherwise - execute whatever you have already set;

This is in very broad strokes. Try it and let us know if there are particular steps that you struggle with.

I did this and the game crashed.

I atleast got it to work but now for some reason it will not go back to chasing after contact

another thing is that my enemy never even returns to find random location state at all it only runs away from light and never returns or chases and attacks player

The top left sequence node is kind of useless since it only has one child. Try moving the LightOn IsNotset decorator to the selector below it, and wire the top selector under root to it.

To make zombie go back to the random moveto seq under LightOn NotSet, try changing the observer aborts settings on the sequence decorator for target checks. On change should probably abort both ways, so it will change behavior immediatly when target is set or cleared. Also, doublechek that the ai controller is actually clearing the Target key when it loses sight (specifics of that will depend on whether you use PawnSense or Perception).

it’s the same as the video though I feel I might have to switch up how it does it because I still cannot find a solution

I scrapped the one I was following and I experimented with my own knowledge this is what I came up with it works but it’s not as fast as id like and its buggy and it picks and chooses

The sphere trace is from the flaslight, right? Instead of just setting a bool on player and sending it via dispatcher when player bumps into zombie, you should probably use a blueprint interface to send message to the traced actor informing it they’ve been lit up. For sphere trace, you’d probably want to trace by objects, with pawn as the type being traced for (so light doesn’t try to scare walls and stuff).

To make a blueprint interface, rightclick in content browser somewhere, mouseover blueprint in create menu, and click blueprint interface in the flyout. Open that, add a function called LitUp or whatevs, compile and save. Next, open zombie blueprint, click class settings at the top, and look for interfaces in details panel. Click add and select the bpi you just made. Hit compile on zombie, then in the My Blueprint panel, there should now be an Interfaces tab below functions. Find the LitUp function, and doubleclick it to implement it as event. You can use the event to set blackboard keys (or well pretty much anything). Here, I just made NPC jump when light hits them:

Also, to make the behavior tree a bit snappier, I’ve found it’s usually best to put combat logic in branches to the left, and passive wander/patrol stuff to the right. Behavior trees execute left to right, so left branches tend to have higher priority. Decorators should fix this, but sometimes it feels like it takes forever to for it to decide to ignore branches.

Now it’s just now I can’t get it to set the value to false any idea how?

In the event where you set blackboard key follow that with a Set Timer by Event, make time like 10s, and wire it to another event to clear blackboard value.

Then zombie will forget about light afer 10 seconds or whatever number you put in time field on timer.

instead of doing that I just created another line trace on false that just ticks the interface Boolean false. it seems to work better than the timer event.