A* Pathfinding Project

AStar Path component in prefab doesn't show field overrides?


#1

I’ve tried searching for something like this, but I haven’t quite found what I’m looking for.

I want to use similar pathfinding settings in multiple scenes. I tried creating a prefab out of the AStar Path, but there’s a problem with that approach. Normally, with a prefab, fields that have been overridden show in bold in the inspector, and can be individually applied. However, with AStar Path, none of the field values show up as overridden. This means I can’t easily see which fields have overridden values, and therefore can’t be individually applied to the prefab. All I can do is apply all changes to the prefab.

Applying all changes seems bad, since (I assume) there are some values on the Path that should be scene specific, like the bounds of the graph.

Anyway, is it possible to make an AStar Path into a prefab, and use it in multiple scenes? Is there some way to get per-field overrides to show up in the inspector?

I also tried making a “preset” out of my object, but it doesn’t apply that AStar Path applies any values in the preset. So maybe that approach just doesn’t work.

I’d also be happy with an explanation of a good way to reuse a similar graph between multiple scenes, ideally such that if I decide my agent’s radius should be a bit different, I can change that in one place, not have to go into every scene and change it on every graph.

Thanks.


Recast Graph data in nested prefab issues
#2

Hi

The graphs do not support prefab overrides I’m afraid. This is because they are not serialized using the Unity serializer (which is pretty limited).

If the fields that you want to change per level are very limited I would suggest that you save the graph to a file (see https://www.arongranberg.com/astar/docs/save-load-graphs.php) and then use a script to load the graph and apply some modifications when the game starts.

using UnityEngine;
using System.Collections;
using Pathfinding;

public class TestLoader : MonoBehaviour {
    public TextAsset graphData;
    public float characterRadius;

    // Load the graph when the game starts
    void Start () {
        AstarPath.active.data.DeserializeGraphs(graphData.bytes);
        var graph = AstarPath.active.recastGraph;
        graph.characterRadius = characterRadius;
        AstarPath.active.Scan();
    }
}

#3

This is just a bug though Aron, it runs contrary to how everything else in Unity works. If I were you I would see what you can do to fix it.


#4

Hi

If I could fix it I would. Believe me I have tried to make the unity serializer do what I need it to do. Unfortunately it also runs contrary to other features like saving graphs to files.
Especially when it comes to saving graphs with node data the Unity serializer falls apart. It cannot handle that much data and will just cause the editor to lag endlessly.


#5

Thanks for the workaround.

One other thing you might consider changing, which applies to various A* components that I assume are serialized using the Unity Serializer, is that your handling of “CaptureContextClick” in EditorBase prevents the ability to right-click on various field and Apply/Revert that change. For example, right clicking on an overridden field in a prefab’s component usually gives you something like this:

image

However, doing the same thing for fields on most A* components instead just gives me this:

image

This makes it awkward to override/revert fields, as I have to go up to the top-level parent and find the change there. Maybe CaptureContextClick could augment the existing context menu instead of creating a new one?


#6

Ah. Right.
The Apply to prefab context menu didn’t exist back when I implemented the Show in online documentation menu. I’ll have a look at that. That’s definitely not the desired behaviour.