AI: Moving to Targets / Giving items to Character?

Hi All

I have 2 questions, both I have got to work but there must be a simpler way.

Game Basics:

Type: Top Down

Event: NPC goes to one location, triggers overlap & collects items, goes to character, triggers overlap and transfers items to Character.

Locations: Possible up to 20 when game complete.

Moving to Targets:
At this stage I have setup 3 buildings, 1 Wood, 2 Metal & 1 Bank. The character can walk up to the Wood & Metal buildings, click on them and the items get transferred to the character.

What I have setup on top of that is now to get AI Pawns to go to the Wood & Metal buildings, collect it & deliver it to me. Now this works, but it is very messy and by the I finish, my blueprint will look a little like someone dropped spaghetti on the floor.

To go to the buildings, I put a Target at the front door, put a ‘TAG’ on it. Then inside the character, did a loop for each and looked for the TAG.But the loop never seemed to find the TAG, and this seems overkill for one Target, but wanted to do this in case I moved the building. At this point I am using ‘Simple Move To Location’ and manually entering the location.

Is there an easier way to do this?

Giving Items to Character:
I have place a Collision around the character, when AI Pawn overlaps, I Cast to Each AI until it finds the correct one, each being fired on ‘Cast Failed’

Now if I have 20 different buildings & items, this would be very hard to amend or debug. Is there anything like a ‘BP interface’ that I could use instead of all this casting?

With Regards

Indeed there is such a thing as the [Blueprint Interface][1], and it could certainly help you clean up the graph in your last screenshot a lot.

Alternately, depending on how you’ve designed your project, you could have each of the different NPC types derive from the same, common ‘parent’ class, and put the common behavior you’re trying to access on that top-most ‘parent’ NPC class. Then, in that case, no matter which kind of NPC triggers the overlap, you can rely on being able to cast it to the common ‘parent’ class, because each individual type derives from it.

Now, as for programming the NPCs to go to various destinations in a clean and organized way, I suggest you look into UE4’s [Behavior Tree][2] system. The [official quick-start guide for Behavior Trees][3] may be especially useful to you. It may not seem “easier” than the method you’re using now, but it’s surely the more robust and future-proof way for you to get your NPC AI working satisfactorily.

Hope this helps!

https://docs.unrealengine.com/en-US/Engine/Blueprints/UserGuide/Types/Interface
[2]: https://docs.unrealengine.com/en-us/Engine/AI/BehaviorTrees
[3]: https://docs.unrealengine.com/en-us/Engine/AI/BehaviorTrees/QuickStart