AI MoveTo fails when target actor is placed later

Hi, I’ve been having a weird issue that I can’t seem to fix for days now.
Basically, I have a counter to which AI customers can come to and order stuff. They walk into the store, the behavior tree sets their next waypoint to a counter and then theyre supposed to move to the queue. This all works fine if the counter is already placed in the world at the start of the simulation, however if I spawn the exact same counter blueprint actor while the game is running, the AI customers will detect it and move towards it (the MoveTo target is set as a locatino of a certain specific SceneComponent in front of the counter), but when they arrive at the location in front of the counter, the MoveTo just fails for some reason and the customer leaves without ordering. But this only happens with newly spawned counters, the ones that had been placed before the game was launched are fine and work correctly. Does anyone have any idea what could be causing this issue please? Thank you!
PS: My NavMesh is otherwise working as it should and it is also set to dynamic and updates every 0.5 seconds.

When is the AI supposed to move away, it has to leave at some point right? If you have coded some behaviour for the AI to leave then check and see if there is any information missing from any of the variables that the AI or the Counter needs at the point where the AI reaches the counter. Have a look at this while the game is running btw and check if any moveto methods are getting false information.

Its a shot in the dark from me but it might help if you’re a beginner, if you have some pictures of your code that you could provide that would be cool.

Hi, thank you for the answer. I’m not sure I quite understand it though, I’m sorry. The AI has a simple task that sets it “MoveToLocation” as a blackboard key (it’s a location in front of the counter). Then it actually starts moving to it, and it stops exactly where it should, on the location. Now you would expect this MoveTo task to be successful, however, it returns failed for some reason - but ONLY with counters that have been placed AFTER the game has already been launched. With counters that had been placed before the game was launched, it works correctly and the MoveTo succeeds.
As for providing screenshots - I wouldn’t even know where to start. I’m not a complete beginner and I have a lot of blueprints set up, there would be a lot of stuff to show. The important bit here is the surprising difference in behavior in the behavior tree between already placed counter and a newly placed counter.

Maybe on event begin play you should set some variables for the counter that the AI calls for somewhere? Have you printed out the information that’s going into the failing MoveToLocation node yet?

Its unlikely that there is some sort of bug from within the engine.

The counter is a solid blueprint actor that is exactly the same whether it has been placed before the game was launched or after, there is nothing different about it. The AI scans the counters only after it has entered the map, so it doesn’t differentiate between them if they are already placed. It is also backed up by the fact that the AI actually DOES move to the MoveToLocation by the counter, as I wrote before. It just returns failed after it is done moving, for no well explained reason. If I set the MoveToLocation manually to some number, it does work and the AI moves to that location and succeeds. But when I load the location of the counter component into that key, it fails after the AI moves there (but only with counters placed later).

Ill test it out to see if I can replicate this behaviour.

I made some screenshots and tried to simplify as much as possible.
Here is the counter blueprint with the SceneComponent (which location we need for the AI to go to) selected.

Here is the part of the behavior tree that sets the blackboard value as a vector to move to, then executes the MoveTo task, which is the one I have issue with (it fails even after the AI moves to the correct location, with counters placed after the launch of the game).

And here is the task before MoveTo that sets the blackboard vector key.

As I previously said, it WORKS for counters that are already placed in the world at the start of the game. But for counters that are placed during the game, the AI moves to the correct spot but the MoveTo task fails right after, for some reason.

Ok this is what I have made.

1 Second into the game we spawn the counter with the scene component.

2 Seconds later the blackboard communicates to the character to walk to the counter.

This is simply me setting the blackboard value.

This is the end result!

It seems to work fine for me :frowning:

So what you are saying is that when you spawn a counter then the “MOVETO” node doesn’t work if the counter is spawned at runtime…? Did I replicate it good enough?

And that the AI, DOES move to its location but the MOVETO node fails?!! HHHmmmm? WHAT?!

I have added a print string after the MoveTo node in the behaviour tree now and nothing is failing :confused:

I think you replicated it well but maybe there’s a setting or idk what that makes my case a bit different, but I don’t know what. That’s what I’m trying to figure out. And yes, that’s the strange thing - it DOES move to the location but then the MoveTo returns failed.

Ok I did more testing and got some more info, but still no idea what’s wrong. If I spawned the counter in the level blueprint after a 5 second delay, it worked correctly. However, I’m using an UI button that you can click and buy the counter with, then you place it in the world. Here’s a quick screenshot in the the player pawn blueprint that creates the actor:

It’s a standard “spawn actor from class” that works if ran from the level blueprint.
But if it’s spawned with this, then moved around by the player until they place it down somewhere, I have the issue mentioned with the MoveTo failing.

Did more testing and found out this - if I spawn the actor from a blueprint, it works. If I spawn the actor with the UI button but not move it around with my moving function, it works. However, if I move around the counter with my moving function (pictured below, in the player pawn BP), it becomes “broken” in the way I described - if an AI moves over to it, the MoveTo task fails even though the AI moved to the right spot. I can’t figure out what could be causing it in this BP.

Ok so I have moved everything into my UI!

Does this reveal anything more to you? It worked for me.
I am having a deeper dive into your code now.

And I have also added a move counter to new location button. And its still working for me!

Hey maybe the location that you are telling the AI to move to is slightly beneath the ground and the AI moves in that direction and gets as close to it as possible but cant get to it fully?

Have you tried setting the ACCEPTANCE RADIUS on the MOVETO node to an unreasonable large amount so that you are 100% sure your AI is reaching it?

And maybe try putting a small red sphere component with no collision onto the SCENE COMPONENT that the AI wants to move to. Just to make sure its like not beneath the ground or anything :expressionless: