Problem with switch on enumeration

So I am working a an AI bot with two states, Search and Attack. I’m using a sphere component to detect enemies within a certain radius. I have attached my blueprints, the issue here is that it shows the log message on overlap withMyCharacter but it doesn’t Switch enumeration to attack state and hence I can’t get my bot to attack. Please help.

Hi,

my 2 cents here:

  1. While it’s not related directly to your question, I wonder if you can, somehow, bind your event once and for all in Begin Play Event in place of making 2 successive cast and the binding in each receive tick.
  2. Regarding the switch and the info you’re providing, I suppose that you enum setup start with the search entry. Tell me if I’m wrong, your blueprint says: If search then your state is 0 (what is 0? search?) otherwise if attacks then state is 1 (what is 1? attack?).
  3. If your enum declaration starts with search then probably 0 is search right? If this is the case then you’re always in a searching state.
  4. Is your behavior tree updating the state as well when needed?

Hello Tensa,

First of all thanks for your response. Here’s my answer to all your points:

  1. Thats a good suggestion, I’ll definitely do that.

  2. Yes, 0 is Search and 1 is Attack

  3. Yes, first enum is Search

  4. Behavior tree is not updating the state either since it is always in Search state

Well,

in the DetectNearby event graph, I see that you are first getting the state from your blackboard, you check its value and…you reassign the same value for the blackboard. Obviously, your behavior tree is likely to execute the same task again and again. In your case the Search Task.

You can try to start with real easy stuff:
In your DetectNeaby Task, set the blackboard key

  • Attack in BeginOverlap (As soon as something enter your sphere, your are in attack mode)
  • Search in EndOverlap (when that component exit the sphere, you are in search mode)

This is really basic of course but at least, you should be able to see your BT logic switching between tasks based on your state enum.

That solved it!
Thanks :slight_smile: