Problem in AI

Hi guys, I’m working to a top down shooter and I’m stuck with the AI.
I found this quick-start guide on the Unreal Documentation:
which is perfect for my project, so I builded up all the blueprints and applied the Controller (Follower AI CON) to my enemy character as the default controller.

I also builded up a simple spawn for enemies, which is the following:

I used an Event dispatcher: There is a trigger box (called Spawn Enemies) that calls this on the level blueprint.
It’s very simple: after the Overlap event, “Spawn AI from class” spawns an enemy, and the number of enemy spawned is increased by one. Until this number is less than the spawn limit value, it keeps spawning. The spawn location of each pawn is choosed randomly from a group of target points placed on the map.

I don’t think this could be the reason of the problem, but since I’ve made it on my own and I’m not very experienced, maybe there is something to change, in order to make the IA working correctly.

I’ll briefly explain how the IA should work: When the enemy is spawned, his location is stored in the HomeLocation variable. If he see the HeroCharacter, he moves to his location. If he loose his target, he stops and waits for 2.5 sec and then returns to his HomeLocation.
What actually happens when I hit play is: If an enemy sees me, he runs to my location. If I make him loose the target, he just stays still and does not go back to HomeLocation. If I make him see me again, he correctly follows me.
When I stop the game, I receive this error log:

And the reason is the Get Controlled Pawn node, as you can see here:

I think that when the pawn is spawned, the controller does not immediately take possess of him, so the HomeLocation variable cannot be stored, (this could explain why enemies don’t go back to HomeLocation) but the fact that the enemy runs to me means that at a certain point the controller “appears”.
So… has someone and idea of why this appens? How can I fix it? I’m really desperate, I tried everything.
Hoping I explained clearly the problem, thank you

Yes, don’t set the BlackBoard value on BeginPlay, set it after the BehaviorTree has started.

Uhm… do you mean something like this?

because does not work yet…

Add a delay at the beginning of your begin play.

Or better, add something that asks if the pawn is valid, if its not it waits 0.1 seconds and tries again until it is.

It works!

Now the Controlled Pawn is valid (I can’t believe it was so simple, I feel a little bit stupid), but HomeLocation results invalid on the behavior tree yet.
This time I can’t really figure out what could be wrong… “When controlled pawn is valid, get its location and store it in HomeLocation”, seems ok to me…
I also tried to swap the “Run Behaviour tree” and “set value as vector” positions (set value and then run the bt) but nothing changes.

Try storing your pawn in a variable and feed that into the actor location pin.

You are right to run the BT first, but Try this:

Instead of wiring the pin straight into setting the BlackBoard value, use a Timer, make an initialize event and call it .1 or .2 after the BT has run.

Hope I did not misanderstood your instructions guys, but it’s still the same with both the solutions: HomeLocation invalid.
These are the blueprints I tried (First one is the Yun-Kun advice, the second one is mikepurvis one):

couldn’t it just be some event that are sent by the behavior tree setup?(I’m out of AI loop a bit, so please forgive me if this is intended behavior)
It seems really odd that you have to rely on a delay function to retry, instead of just use event chains to setup everything properly.

EDIT: after recheck OP, it seems that you can derive a AI Controller to make your life easier if a valid controller is essential for your event flow. So there should be a Event On Possess for you to use after a AIController is spawned and hand over possession of your AI Pawn.

Keep your setup.

Remove your “use blackboard” node.

Just run your BT like you do, adding the key afterwards.

If it doesnt work, try the PenguinTD’s logic.

I never used the “set blackboard” node, I have a feeling that it is supposed to be used if you want to switch from the original blackboard you set up in your behavior tree. But I’m not sure.

I tried to remove the UseBlackboard node as Yun-Kun said and the beahaviour tree works as normal, so it was clearly useless.
…but HomeLocation is still invalid.

I didn’t get the PenguinTD’s logic, what do you mean? How should I use the Event On Possess?

You should follow that video.

He’s basically doing what you want to do I believe.

I watched the video and noticed that he links anything to the get blackboard node. So I did and… it works now! I just basically removed the self reference, I don’t even know why it was there…
I mean, the blueprint is a controller class, so what is the point to use a self reference of a blackboard…?

Anyway, the final blueprint is the following:

I really have to thank you for the help guys, you have been so kind!

I followed the same ‘tutorial’, but it ends up being a mash of unorganized references. I also do not think it uses the AI tree correctly (try issuing a new command while in the middle of one, didn’t work for me) Also had issues with the AI moving to world origin on spawn and under certain conditions (when MovetoActorOrLocation has null for an actor reference).
This is my setup: (open images in new tab, they are large)

AI Tree + AI Controller:
AI Tree Service:

I’ve noticed that, we had a lot of troubles on making it working correctly, and I can’t even say in does now. Everything’s fine until we have one or two enemies on the map, but when they are a few more and they touch each other to reach the same location (for example, TargetToFollow) it seems like they loose their HomeLocation value, infact if you make them loose their target, some of them go back to HomeLocation as expected, some others just stay where they are until they’re alive.

What about your setup? I’m quite noob yet, it makes IA move to mouse location, like a strategic game?

To anyone who still have the invalid HomeLocation blackboard key -> you might forgot to set the default value of the HomeLocation name variable.