# Making my AI more compact

**URL:** <https://forums.unrealengine.com/t/making-my-ai-more-compact/472731>\
**Category:** AI\
**Tags:** unreal-engine, cast, pawn, question\
**Created:** [October 10, 2020, 7:47pm UTC](https://forums.unrealengine.com/t/making-my-ai-more-compact/472731 "2020-10-10T19:47:12Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ralfetas](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ralfetas](https://forums.unrealengine.com/u/ralfetas)\
**Post date:** [October 10, 2020, 7:47pm UTC](https://forums.unrealengine.com/t/making-my-ai-more-compact/472731/1 "2020-10-10T19:47:12Z")

</div>

Hello!

I am working on my first project in Unreal, i will have around 20 npcs with their own routine, looks, house location, they go to work, eat, etc…

I made a master BP with the basic information, and a child for each NPC, i would like to use one AI BP for all and adjust the routine based on the pawn variables, so far so good, the pawn adjust the variables on the AI BP.

I face a problem when i need to fire a event from a task or ai to the pawn, for this i would need to cast to the pawn.

What would be the best solution for this?

I think about spawn the NPC´s from one BP, or just building 20 ai´s and behavior trees, but i would like to keep the 20 individual BP´s to fine adjust everyone. About performance, would have a different using 20 different behavior trees?

Thanks for any help!

---

<div class="post-metadata">

**Author:** ![Detach789](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Detach789](https://forums.unrealengine.com/u/Detach789)\
**Post date:** [October 11, 2020, 12:01am UTC](https://forums.unrealengine.com/t/making-my-ai-more-compact/472731/2 "2020-10-11T00:01:54Z")

</div>

This sounds like something you could use an interface for. That way, you could just call the interface to tell the NPCs to “do something,” but each individual NPC may interpret “doing something” differently. 🙂

---

<div class="post-metadata">

**Author:** ![ralfetas](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ralfetas](https://forums.unrealengine.com/u/ralfetas)\
**Post date:** [October 11, 2020, 12:43am UTC](https://forums.unrealengine.com/t/making-my-ai-more-compact/472731/3 "2020-10-11T00:43:31Z")

</div>

Thanks for the reply!

Indeed the interface could help this, would be a way to set controlled pawn in the task BP as a variable so only the correct one would fire?

Just to clarify, this event is to change clothes, so if the npc go to work, this task will be together with the vector.

---

<div class="post-metadata">

**Author:** ![ralfetas](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ralfetas](https://forums.unrealengine.com/u/ralfetas)\
**Post date:** [October 11, 2020, 12:51am UTC](https://forums.unrealengine.com/t/making-my-ai-more-compact/472731/4 "2020-10-11T00:51:14Z")

</div>

I will try something later, from the controlled pawn i can add a tag, i will try to add a tag like “changestyle”, fire the interface, on the pawn validate the tag, back in the task remove the tag, and finish it. Will report if this works, or will use any other idea 🙂  
Thanks again!

---

<div class="post-metadata">

**Author:** ![Detach789](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Detach789](https://forums.unrealengine.com/u/Detach789)\
**Post date:** [October 11, 2020, 12:57am UTC](https://forums.unrealengine.com/t/making-my-ai-more-compact/472731/5 "2020-10-11T00:57:12Z")

</div>

I’m not sure I quite understand how your interactions are set up.  
I do know that interfaces work in most cases when you want different actors to do different things from the same type of call.

---

<div class="post-metadata">

**Author:** ![ralfetas](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ralfetas](https://forums.unrealengine.com/u/ralfetas)\
**Post date:** [October 11, 2020, 1:57am UTC](https://forums.unrealengine.com/t/making-my-ai-more-compact/472731/6 "2020-10-11T01:57:30Z")

</div>

I made a very simple system, is just switch, 1 work, 2 casual etc… Each number change the body mesh, nothing fancy.

---

<div class="post-metadata">

**Author:** ![ralfetas](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ralfetas](https://forums.unrealengine.com/u/ralfetas)\
**Post date:** [October 11, 2020, 2:21pm UTC](https://forums.unrealengine.com/t/making-my-ai-more-compact/472731/7 "2020-10-11T14:21:27Z")

</div>

In the end, i don´t even have to use the tag… i think i need to learn more about interfaces hahahahaha just the interface works like a charm, i don´t even had to make the branch to validate the tag, don´t know why, but they only fire the interface in the controlled pawn, important is that this works, so i will have 19 less tasks BP to adjust 🙂

Thanks for the help!
