Hi! I really like the Procedural example (I asked about it years ago and finally noticed that you’d done it ), but I’m curious if it’s even possible for it to work with LayerGridGraph. It’s more important to me that it work procedurally than work with layers, so if you’ve tested it out or know that someone else has figured it out, I’d love to know. Code would be amazing!
TL;DR - Can LayerGridGraphs work when you update the graph at runtime, like the in Example 12?
Hi. Sorry, there is no implementation for that at the moment.
Not quite sure what you mean by that. The whole point of the LayeredGridGraph is to support layers.
Thanks for the quick reply!
Okay, I figured you didn’t have any code for it, but is it possible? Do you think I could hack it to get it to work?
What I meant by the second statement was that if I can’t get LayerGridGraph to work with ProceduralGridMover, I’ll just use GridGraph with ProceduralGridMover instead.
Sure, it’s possible. I think one can essentially do for each layer what is done for the grid graph. But it will take some work to write and unfortunately I do not have so much time right now.
1 Like
That’s understandable. If I get a chance to do it, I’ll share the code. Thanks!
Hi Aron! With some code from ProceduralGridMover to change the center, I’ve been able to get LayerGridGraph working with the normal Astarpath.active.Scan() or ScanAsync (Loop). Even updating via a bounds works. That said, all of these update methods seem to take place within a single frame, taking something like 80ms to do 22k raycasts in my case.
Is there an easy way to split up the updates across several frames? I’d be perfectly happy if it would update in a half second or more, as long as it didn’t affect the framerate.
I think I got it. I copied ScanInternal in LayerGridGraph, and added a bunch of yield returns in it in various places, then called it like UpdateGraphCoroutine was being called in ProceduralGridMover. It seems to be working!
Edit: I also had to create a point graph for the nodelinks, and update that one as well, then call the postscan processor thing afterwards to make sure it links into the layergridgraph. I just followed how the code works for AstarPath.Scan()
1 Like
Hey superdupergc, I just purchased this asset and a LayeredGridGraph that follows the player sounds like what I need. Anyway you can post the changes you did to get it working?
Really, just go into LayerGridGraphGenerator.cs (under AstarPathfindingProject/Generators/), copy the ScanInternal function to a new ScanInternalCoroutine() function, then add the following code after every For loop in that function: yield return new Progress();
You also need that ProceduralGridMover script to call that coroutine the same way you call the update for GridGraph, except it’s basically going to rescan the entire graph every time. Adding the yields spreads the update out over several frames, which helps the framerate, but this is still pretty slow and it’s NOT easy on the garbage collector because of how many raycasts you’re doing (it’s like, 20k for my setup)
Here’s my code -
https://dl.dropboxusercontent.com/u/8020834/Astar/LayerGridGraphGenerator.cs
https://dl.dropboxusercontent.com/u/8020834/Astar/ProceduralGridMover.cs
I’m actually not using this plugin anymore, but I’m happy to share my work. You can find me on twitter as @superdupergc if you run into any trouble.
I was able to follow your posts and got this to work. Its a bit too slow for me. I am starting to look into how to convert the ProceduralGridMover to work with LayerGridGraphs and I see why this isn’t part of the package yet, its a bit complicated
@aron_granberg, whats the best way to go about this? Would it make sense to hardcode the amount of levels and just leave them null so that I don’t have to worry about array size changing when resorting the array? If not, is it possible to first resort the array and then reuse code from UpdateArea to update the nodes that need to be refreshed?
I started to toy around with the idea of hardcoding the layerCount and got it to execute without nulling but it fails to create more than 1 level. I don’t understand all of the code completely yet.
I managed to get this to work properly.
I had to change the following:
- Add layerIndex to the grid reorganization in UpdateGraphCoroutine
- Change UpdateNodePositionCollision to use logic from RecalculateCell. Send nodes by ref
- When adding a new layer, add it to a reference of nodes, not the grid’s nodes
- Change CalculateConnections to LayerGrid version
- After update all nodes in move function, set graph nodes to this array
- Call post stuff. Forget if this was necessary
I might have forgotten something but that was basically it. It can now scan procedural worlds with layers quickly.
Hi
I took some time to (finally) write a procedural grid graph mover that works for layered grid graphs as well.
If anyone want to try it out you can PM me and I will send you a preview version.
1 Like