UPDATE:
I may have figured something out. I was playing around with AstarParth.Scan() and found that if I Scan() at the start of my game, ProceduralGridMover.UpdatePath() seems to behave as expected (even for scenes outside the current bounds of the grid oddly enough).
I suspect that this might have something to do with me caching the grid, which I don’t totally understand to be honest. I’m going to run a Scan at the start of my game and then hopefully I’m good to go?
UPDATE 2: Sorry for all the edits…it’s still a little finicky and I think the update above is more of a band-aid solution. I suppose I can run AstarPath.Scan() when I need to, it’s just that it seems to lag a bit more than ProceduralGridMover.UpdatePath()
/original post below/
Hey Aron, I’ll try and keep this simple…
My game world is divided up into scenes that are loaded additively as the player moves around. Basically each scene has a “scene node” object, and when the player moves close enough to that node it will trigger the loading of all surrounding scenes and the unloading of any scene a certain distance away.
I have a method that:
-
Loads a scene
-
Waits for that scene to be loaded
-
Loads the next scene, ect.
-
Then it loads all of the “harvestables” (think trees, rocks, etc) for that scene
-
Then I call ProceduralGridMover.UpdatePath() to update the grid
This is all in a coroutine that waits for each scene to be loaded before progressing.
The grid successfully updates allowing the ground to be walkable but seems to ignore the rocks and trees and such. If I load the game from the title screen these same rocks and trees will be accounted for in the grid, but if I walk away from them and come back they are no longer counted…the rocks and trees are actually the same instances, I just activate/deactivate them whenever their scene is loaded…
I’m wondering if you might have any ideas on what might be causing this? Maybe my couroutine isn’t playing nice with the ProceduralGridMover?
I should also note that I set the update distance to 10000 because I wanted to update the grid manually. Previously I was having an issue where the scene terrain itself would not be counted because it was loaded after the last update (based on player distance from the grid center).
Thank you. Below is the code. It may be ugly by your standards I apologize.
IEnumerator WaitForSceneLoad(List<string> scenesToLoad)
{
//HarvestableSpawnPoints live in each scene and will add themselves to this list so they can be activated after all scenes are loaded but before the grid update
harvestables = new List<HarvestableSpawnPoint>();
for (int i = 0; i < scenesToLoad.Count; i++)
{
AsyncOperation asyncLoad = SceneManager.LoadSceneAsync(scenesToLoad[i], LoadSceneMode.Additive);
// Wait until the asynchronous scene fully loads
while (!asyncLoad.isDone)
{
yield return null;
}
}
for (int i = 0; i < harvestables.Count; i++)
{
harvestables[i].LoadHarvestables();
}
//yield return new WaitForSeconds(30f); //try and wait for everything above to finish..?
Pathfinding.ProceduralGridMover grid = ApplicationManager.GetInstance().GetGridMover();
grid.UpdateGraph(); //wait until this is done too
while (grid.updatingGraph)
{
yield return null;
}
levelsAreLoaded = true;
Debug.Log("levels are loaded");
}