- A* version:
5.3.7- Our project fixed this version as dependency, requires back porting if patch needed.
- Unity version:
2022.3.62f3
Hello,
I am the engineer responsible for optimization in our company.
Since we had to started separate AstarPath’s AstarData into individual levels as cache files, following below thread.
- Title : Question About AStarPath Graph Loading Structure and Optimization
- Thread ID : 18814
This is new account so I can’t post URL yet.
(admin edit: Question About AStarPath Graph Loading Structure and Optimization)
Note that I don’t want to necroing thread so I wrote up this thread.
However, the current workflow that made by me, is having some trouble for automation in our ends so I’m looking for solution about our problems.
TL;DR
- I want to figure out what should I have done before and after for proper way to handling
AstarPath.data(AstarData) or scanning.- Proper way to switching active instance while multiple instance exists for it.
- Proper way to transfer scanned graphs data.
- I want to use
AstarPatheach level only for editor, for simplifying workflow for co-workers.- Able to use same inspector interface.
- Supporting Gizmos.
- Able to scanning graph and serializing data to cache file independently from main
AstarPath. - Holding graphs settings only.
- I made handler component that supports for these problems.
- We can provide source code of this component and editor if needed.
Background
- Our project is 2D, top-down view, with multiple layers for depth, using Z axis.
- We want to optimize memory, loading time and performance for
AstarPath. - Current setup is centralized, every level’s graph are stored into single
AstarPath, which is may suppose to used like this.- However, this causes huge processing time due loading to memory and deserialization.
- We have 40 graphs.
- Some level have multiple graphs for storing each Z layers’ graph.
- I planned to utilize
AstarData.DeserializeGraphsAdditivefor separating graphs each level.- So I made handler component that uses
AstarPathwithin editor only purpose.- That
AstarPathwill used for…- Scanning graphs for it’s depending level and save cache.
- When it awake or being destroy on play, handler append or remove cache graphs to active
AstarPath. - Simplifying workflow, I indented workflow that our co-worker will use same interface for each level to setting up graphs.
- Supporting visualization through Gizmos.
- Since handler’s
AstarPathis only editor purposes, it’ll be destroyed at awake on play.- Also wouldn’t be saved for build, using
HideFlags.DontSaveInBuild. AstarPathwill stores graphs without nodes data, I utilized serialization with settings at saving scene.
- Also wouldn’t be saved for build, using
- That
- So I made handler component that uses
The problem
- According to documentation (Saving and Loading Graphs, again, I can’t post links),
AstarPathis assumed to be singleton, there’s various fail-safe for most of APIs.- This made some trouble to juggling two or more
AstarPathinstances even in edit mode.- This is the main reason that I want to looking for proper way to scanning/handling data with this scenario.
- This made some trouble to juggling two or more
- What I want to achieve is below :
- Scanning specific
AstarPath- I think it’s possible with disabling all of instances and enable single instance for scanning.
- Serialize graphs
- I have no idea but it throws various exception or error that intended to be fail-safe for singleton.
- I also think it’s possible with ‘Scanning specific
AstarPath’s way.
- Migrate graphs between two
AstarPath- Since we are planning this for reduce loading time and memory optimization purpose with keeping workflow simple, I want to main
AstarPathdoesn’t have any graphs at all in initial state and feed them from handler component from each levels. - I’ve tried batch migration from main
AstarPath’s graph data and I haven’t achieved my goal yet.- Open single scene that has main
AstarPathinstance. - Load all levels that requires main
AstarPathto scan. - Transfer to each level of
AstarPathwith serialize and deserialize scanned data. - Level’s
AstarPathhas graph settings but it doesn’t have nodes data, I don’t know what it causes.- I used
SerializeGraphsby reflection (it’s for just in case for future proof, I don’t want to modify code base as possible) withSerializeSettings.NodesAndSettingsfor specific graphs of mainAstarPath’s data.
- I used
- Open single scene that has main
- Since we are planning this for reduce loading time and memory optimization purpose with keeping workflow simple, I want to main
Side notes
- Juggling two or more
AstarPathinstances in editor for handing data is cumbersome for developer UX.- Current workaround is disabling all instances and enable single desired instance.
- I must assign desired instance to
AstarPath.activemember before performing APIs, it made boilerplate on batch automation codes in ours.
- Mixture between editor and runtime logics makes hard to figure out what should I have done before and after on handling data.
- I’ve seen some comments around code bases, there’s lots of care point to handing data or instances so I want to figure out proper way to manage them.
Thanks for reading my long summary on our situation and problems.
