Problem with scenes with more than two targets

Hi people. I have the pro version, actually i’m trying the last beta. In this version or in the last release I have the same problem. I have too many characters following many targets in my scene, but, just the last two targets are working

For example: If I put 20 characters in my scene, 10 of them following the T1 target, and the other 10 following the T2 target, all works fine, but if I put 20 more, following targets T3 and T4, only these 2 targets will be followed, T1 and T2 stop working.

Any idea about this?

Hi

What kind of movement script are you using?
Is it a custom written one or the built in ones?

If it is a custom written one, make sure you are not requesting new paths before the previous one has been calculated since that could cause it to never get any calculated paths back if the latency between requesting a path and getting back the calculated result is high enough.

Hi, for the movement just AIPath, I’m not writting any custom code. I’m cloning a character and setting the target. I have many walkways and many characters, all the walkways are a navmesh grid. I put a target at the end of each walkway, but only the last two still working

this is the code.

`private static void AddCharacterOnWalkwaysStart()
{
if ((Time.timeSinceLevelLoad - timeLastActoresAdd) > 5f)
{
for (int i = 0; i < Walkways.Count; i++)
{
GameObject bman;

            //Put the character at walkway start
            bman = (GameObject)Object.Instantiate(GameObject.Find("BMan"), Walkways[i].Segments[0].FirstRowPoints[0], Quaternion.identity);

            bman.transform.LookAt(Walkways[i].Segments[0].LastRowPoints[0]);

            //set the target of AIPath at the end of the walkway
            AIPath aiPathScriptBman = bman.GetComponent<AIPath>();
            aiPathScriptBman.speed = 1.09f; 
            GameObject targetBman = GetOrCreateGameObject("Target" + i.ToString());
            targetBman.transform.position = Walkways[i].Segments[Walkways[i].Segments.Count - 1].LastRowPoints[0];
            aiPathScriptBman.target = targetBman.transform;
            aiPathScriptBman.SearchPath();
        }
        timeLastActoresAdd = Time.timeSinceLevelLoad;
    }
}   

`

Hi

The AIPath script will search for the path to the target every few seconds (depending on what the “repathRate” variable is set to), so if the target has moved to another location after you requested the initial path, it will try to move towards the new position of the target. Make sure their target is always at the correct position.

Are you getting any path errors? (set A* Inspector -> Settings -> Path Log Mode = Normal).

You don’t really need to call the SearchPath function, the AIPath script does (as mentioned) repeatedly search for the path to the target.

I don’t moving targets, I’m creating new targets.

each 5 secconds I create a new character foreach path, and I set the target for this new character to the end his path, This is the same for one path, or two, but when I create de third path, the first one stop to work.

Ok, I was just wondering since I saw the function GetOrCreateGameObject(“Target” + i.ToString()); which would imply that you reused targets.

Do you think you could send me an example project for this, I can’t see anything wrong with the code.

Hi

Got your shared video. However I meant a project in unity that I could debug. A video doesn’t tell me much.