Support Forum

Using two graphs symultaneously

I am trying to mix two graphs - one is general for entire terrain (grid graph), the other is for roads that would allow faster movement (point graph).
I tried to update some of existing example scenes by adding another graph but with no visible result despite using high penalty for grid graph.
Perhaps I do not need grid graph at all?
A hint what I should do?

Hi

Using two graphs like that is not usually recommended because it’s quite tricky in my experience to connect the two graphs in a good way. Instead, I’d recommend “painting” penalty on top of the grid graph. If you have the pro version you can do this directly in the grid graph. In the beta version it’s called “Grid Graph Rules”, in the non-beta it’s called “Penalty Modifications” (I think, haven’t checked the UI for that lately, it’s at the bottom of the grid graph settings anyway). See also https://arongranberg.com/astar/docs/gridgraph.html#textureData

Thank you for your reply Aron,

I tried to use Texture data on example2 but so far with no success.
There is couple points I would like to discuss:

  1. Button Generate Reference calls SaveReferenceTexture where I get error in following code block:
    using (var outstream = new System.IO.StreamWriter(path)){
    using (var outfile = new System.IO.BinaryWriter(outstream.BaseStream)){
    exception ==> outfile.Write(tex.EncodeToPNG());}

<695d1cc93cca45069c528c15c9fdd749>:0
at System.IO.StreamWriter.Flush (System.Boolean flushStream, System.Boolean flushEncoder) [0x00094] in <695d1cc93cca45069c528c15c9fdd749>:0
at System.IO.StreamWriter.Dispose (System.Boolean disposing) [0x00022] in <695d1cc93cca45069c528c15c9fdd749>:0
at System.IO.TextWriter.Dispose () [0x00000] in <695d1cc93cca45069c528c15c9fdd749>:0
at Pathfinding.GridGraphEditor.SaveReferenceTexture (Pathfinding.GridGraph graph) [0x001be] in D:\Unity Projects\NewProject\Assets\AstarPathfindingProject\Editor\GraphEditors\GridGeneratorEditor.cs:575
2. Despite this error reference png file is being created.
3. Although file is being created I do not see my source file to have any impact - result file contains only terrain info.
4. Modifying reference png file does not seem to have any impact neither.

image
image

Help please :slight_smile:

Another thing - is that possible to use pathfinding on two or more terrains? If so, how do I configure it?

Thanks,
Marek

Hi

That error is strange, I haven’t seen that before. Is that the full error? There doesn’t seem to be a message associated with it.

Using your settings the graph should be modified… Not sure why it is not. How big is your texture? In your version 1 pixel corresponds to 1 node.
One thing you might be interested in is that in the beta version the texture modification code has been updated to be faster and the UI is easier to use.

You are right… it is not full error… here it is:

System.ObjectDisposedException: Cannot access a disposed object.
Object name: ‘Stream has been closed’.
at System.IO.FileStream.Flush () [0x0000d] in <695d1cc93cca45069c528c15c9fdd749>:0
at System.IO.StreamWriter.Flush (System.Boolean flushStream, System.Boolean flushEncoder) [0x00094] in <695d1cc93cca45069c528c15c9fdd749>:0
at System.IO.StreamWriter.Dispose (System.Boolean disposing) [0x00022] in <695d1cc93cca45069c528c15c9fdd749>:0
at System.IO.TextWriter.Dispose () [0x00000] in <695d1cc93cca45069c528c15c9fdd749>:0
at Pathfinding.GridGraphEditor.SaveReferenceTexture (Pathfinding.GridGraph graph) [0x001be] in D:\Unity Projects\NewProject\Assets\Assets_AI\AstarPathfindingProject\Editor\GraphEditors\GridGeneratorEditor.cs:575

I had source texture smaller than grid size, but when changed it to be the same size the same thing happens.
Is there example available for penalty modification usage?

I wanted to try with beta version, but did not find it:

Thanks,
Marek