AI not moving if spawn function called from timer.


I’m busy learning my through UE4 atm. I’ve a simple ai that goes from point A>B>C etc… Until it reaches the final point. This is working fine with placed actors and actors spawned with a “direct?” function call. However, when the spawn function is called from a timer the spawned actors don’t move.

Blueprint that calls the spawn function.

The first call to SpawnEnemy spawns an actor and it moves, the calls from the timer spawn the actor, but they don’t move. I’ve had 3 - 4 placed in the world manually and they all move fine, including the one spawned from the non-timer call. If only the timer is called, nothing moves.

Spawner BP

AI Construcion

AI Event

We had issues with AI spawned via timers and the perception component.
I wonder if this is similar.
I’ll pass this link onto our AI guy (@zoombapup).
Hopefully he can chime in with an actual fix for you.

Your best bet for this kind of thing, is to break out the “Visual Logger” and see what the AI is doing (or failing on).

The other thing is to make sure you check all of your values by adding a breakpoint at all the parts which could affect the move call. So specifically, add a break on the moveto and hover over the inputs. Do they seem sane? Is there actually a move target etc.

If the move is failing, it will show up as a fail in the visual logger, usually with a bit of help on WHY its failing. That should help you figure it out!

Thanks for the response. I’ll do some more debugging when I get home tonight.

From the debugging I’ve done I found that “Get Controlled Pawns” returns an empty/null value. Self and CP seemed to be fine. However, you have a good point. I’ll do some sanity checking :D.

Okay, I’ve had a look at the values when it breaks on the Move To function. The Pawn is None. The visual debugger is also showing Pawn as None for MyAI_C_1 (or something like that). MyAI_C_0 has a Pawn and also had a pawn when the breakpoint was reached on the AI Move To function.

I then tried this

And the second actor did not move. Same thing as before, Get Controlled Pawn return None, Move To function Pawn = None

I then tried a simpler example.

Now no actors moved, and first break had the same Pawn = None issue. So it would seem for some reason the AI isn’t possessing the pawns when a delay is involved?

Just to make sure I wasn’t insane I did two spawn calls without a delay.

Both AI moved. It was beautiful. Then 5 seconds later that silly non moving one appeared from the timer :(.

I’ve added the visual logger files (Don’t know if they are of any use…) (3.21 KB)

I have found the solution and feel rather silly.

It is definitely some timing issue. The move function is called before the pawn is possessed… So instead of using Event BeginPlay I used Event OnPossess.

Now all is well with the world.