Local Avoidance doesn't work when creating new AI from prefab

Hi there! I bought the pro version for the local avoidance support and everything was working great until I started cloning the AI.
So basically I have a 2d Turret defense game where the enemies will maneuver through the path created by the user. I followed the 2d pathing tutorial for the 2 agents I had for my example scene. Then, I added the RVO simulator, controller and Navmesh and everything worked fine for my 2 guys running the path. They would move to the target, avoid the towers and each other. I decided to move on to spawning new agents like a normal round of a turret defense game to see how that worked but for some reason the newly created agents don’t have any local avoidance. Every component for the clones is the same as the 2 starter ones but right now the scene has all the “clones” following a path but not avoiding each other but the 2 that start in the game before the cloning are only avoiding each other. Is there some method I should be calling every time a new agent is put into the scene? I’ve tried experimenting to see which but kinda hitting a dead end. Any input is appreciated, thanks!

*Edit. To clarify, these clones are made during runtime. Not sure if I explained that very well lol


Do you clone a prefab, or do you try to clone an already existing unit?
Do you get any error messages?

Hi Aron,

Thank you for replying!
It is creating the unit from a prefab. There are no errors or messages when created and there are no errors or messages when they cross over each other. So, something I realized was that I have the RVO simulator on each agent. Looking through the documentation I see that there is only supposed to be one RVO simulator script (which is attached to the RVO object in my scene). I disabled the RVO simulator on my agents and now they don’t move at all. The path is generated for them and they will still angle towards the target when I move it around.
I feel like there is just one simple thing I’m missing so I will list all the pathfinding components my agents have:
Seeker, AIPath(2d,3d), AIDestinationSetter, RVOSimulator (Though I disabled it for now as stated above), RVO controller, and Simple Smooth.
My RVO Object has RVO simulator and the RVO navmesh.
My A* object only has the Pathfinder component (The one making the grid).

Edit: So, when I created the prefab of the agent that is moving, in order to add the target to the public variable of the AIDestinationSetter, I created a prefab of the target as well (Since prefabs can only reference other prefabs or assets on not objects directly in a scene). When I enable the RVO simulator for all my agents so they will start moving again and move the target around, the newly created agents do not follow the target. I’m guessing this is due to the transform they are referencing is just from the prefab and it isn’t technically the one in the scene. Might just have to create a script to set the target in the AIdestinationsetter when the agent is first spawned in.

Yeah you should only have a single RVOSimulator in your scene. You can remove all the ones on the agents themselves.
And yes, if you reference a target object that is just a prefab, they will try to move to the position that is set in the prefab, which is probably not what you want.

So I removed the RVOSimulator from all the agents and now they collide/avoid each other as expected but for some reason they are no longer following their path. They will try to move in a straight line toward the target till they hit a wall even though my scene view shows they have a path accurately getting them to the target. When they get close to a wall they kind of start doing this back and forth dance every half a second (I’m guessing based on my path recalculation interval) until they touch the wall due to being squished by the agents behind them.
I didn’t realize that disabling the RVOSimulator component was not the same as removing it from the GameObject entirely so, one problem is fixed but another has appeared.

So, I’m not sure what changed. I didn’t work on the project for a few days. Came back to it and they now avoid each other and follow the path as expected. Thanks for all the help!

1 Like