Novice Learning: Run Files at Runtime

Hello,

I have a system that loads scenes with terrain’s within them with async loading once the player reaches a certain distance from the targeted area to load.

My goal: traverse multiple scenes of terrain with a water object between them that the player resides in 3d space with 256 by 256 terrain width size, then modify Astar runtime data while loading new data points with removing old data points as the player traverses.

Player and AI both use Astar pathfinding.

I understand that I can save files that are generated with pathfinding; however, I don’t know how to combine them at runtime then unload files that are not needed anymore so that A star will be satisfied.

Can someone help a novice like me understand on how to bridge these files together at runtime?

General idea of script sudo code that I need help understanding:

Once terrain async is loaded
1.) Run function for loop injecting new file data into Astar //from newly loaded area
1.A) Run an Update for Astar with existing data
2.) Run function for loop removing old file data into Astar //from previous loaded areas
2.A) Run an Update for Astar with existing data

I’ve found the documentation on how to additively serialize the data with: AstarPath.active.data.DeserializeGraphs(loadgraph1.bytes); //to load extra textassets

But it seems like the only way per the documentation is to run:
data.RemoveGraph(myGraph); //removes the entire Astar graph

For the last part:

Is there a way to compare the active.data from a previously loaded TextAsset to then loop it and compare if the active.data has the byte info then simply remove it to unload the specific TextAsset?

I’d rather not do a huge clear all on the entire graph then rerun each TextAsset within a 600 distance to rebuild it.

As a side note, I’m glad the agents do not simply error out if the graph is removed but will fulfill their goal while the graph has time to reload.

Hi

Have you checked out the example scene called Procedural? That might be an alternative solution for you that could be easier to work with.

Hey Aron,

I have looked at that project extensively and I must say it is incredibly well done. I’m still processing my mind on your function that gathers new data information then removes the old nodes. Great work (Since I’m novice it’ll take me a while to figure it out lol but we will get there eventually.)

My logic was thinking a grid is not meant for big 3d maps I’m glad I’m mistaken now. Though this kind of changes the dynamic of my AI spawning system; instead of, spawning based on the terrain scene. I’ll have to setup a bunch of locations and activate them when player gets in range.

1 Like