# Problem with switch on enumeration

**URL:** <https://forums.unrealengine.com/t/problem-with-switch-on-enumeration/301572>\
**Category:** Platform & Builds\
**Tags:** Switch, enumeration, unreal-engine, question, Blueprint\
**Created:** [December 14, 2014, 3:59pm UTC](https://forums.unrealengine.com/t/problem-with-switch-on-enumeration/301572 "2014-12-14T15:59:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![GameEon\_Infotech\_Pvt.Ltd\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@GameEon\_Infotech\_Pvt.Ltd\_1](https://forums.unrealengine.com/u/GameEon_Infotech_Pvt.Ltd_1)\
**Post date:** [December 14, 2014, 3:59pm UTC](https://forums.unrealengine.com/t/problem-with-switch-on-enumeration/301572/1 "2014-12-14T15:59:39Z")

</div>

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.

 ![23993-detectnearby.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/9/2/292dc14947f9b938a2be6b8768ddb9f50d6112fb.png)

 ![23991-behaviortree.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/0/6/40663631e66e1ec53541a86a85fbbf8b2408bd01.png)

---

<div class="post-metadata">

**Author:** ![Tensa\_Zangetsu](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Tensa\_Zangetsu](https://forums.unrealengine.com/u/Tensa_Zangetsu)\
**Post date:** [December 14, 2014, 4:32pm UTC](https://forums.unrealengine.com/t/problem-with-switch-on-enumeration/301572/2 "2014-12-14T16:32:14Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![GameEon\_Infotech\_Pvt.Ltd\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@GameEon\_Infotech\_Pvt.Ltd\_1](https://forums.unrealengine.com/u/GameEon_Infotech_Pvt.Ltd_1)\
**Post date:** [December 14, 2014, 4:48pm UTC](https://forums.unrealengine.com/t/problem-with-switch-on-enumeration/301572/3 "2014-12-14T16:48:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Tensa\_Zangetsu](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Tensa\_Zangetsu](https://forums.unrealengine.com/u/Tensa_Zangetsu)\
**Post date:** [December 15, 2014, 11:10pm UTC](https://forums.unrealengine.com/t/problem-with-switch-on-enumeration/301572/4 "2014-12-15T23:10:33Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![GameEon\_Infotech\_Pvt.Ltd\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@GameEon\_Infotech\_Pvt.Ltd\_1](https://forums.unrealengine.com/u/GameEon_Infotech_Pvt.Ltd_1)\
**Post date:** [December 19, 2014, 4:32pm UTC](https://forums.unrealengine.com/t/problem-with-switch-on-enumeration/301572/5 "2014-12-19T16:32:48Z")

</div>

That solved it!  
Thanks 🙂
