SimpleGraph doesn't show up in Add New Graph list

I’m attempting to follow the instructions here https://arongranberg.com/astar/documentation/dev_4_1_5_3cb9f189/writing-graph-generators.php to create a graph generator.

The steps I followed are:

  1. Install A* to a folder in my project.
  2. Create an empty game object and add an Astar Path component. Once I do, I see the “Add New Graph” area with three buttons “Grid Graph” “Point Graph” and “Navmesh Graph”.
  3. Copy and past the “SimpleGraph” code into a file named SimpleGraph.cs.

After following these steps, no additional greyed out button appears in the Add New Path area.

Am I missing a step? Do i need to “refresh” things somehow? Does SimpleGraph.cs need to be in a specific folder or something?

Hi

It looks like you are on an older version (judging from the documentation link).
This bug was fixed in 4.2.5.

Fixed custom graph types could not be used if they were in another assembly

Thanks for the quick reply!

I definitely did have a much older version going in this project, but attempted to upgrade to 4.2.11 last night in part to address this bug. (I encountered the old documentation link via google).

I did the upgrade incorrectly at first by double clicking the Unity package file that came with the download before deleting the old verson’s folder. I then deleted both new and old versions and re-added the new version.

It’s possible I screwed my back-and-forth or something else screwed the update up somehow though. Do I need to do anything with Unity’s package manager? Is there some way to check the A* version # actually running?

Thanks!

I found the “About” section in the Inspector, I am apparently running 4.2.11.

That’s strange…

Can you post the exact script you are using?
Are you using assembly definition files?

Here is the script:

using System.Collections.Generic;
using UnityEngine;
using Pathfinding;
using Pathfinding.Serialization;
using Pathfinding.Util;

namespace Pathfinding
{
// Inherit our new graph from the base graph type
    [JsonOptIn]
    [Pathfinding.Util.Preserve]
    public class SimpleGraph : NavGraph {
        protected override IEnumerable<Progress> ScanInternal () {
            // Here we will place our code for scanning the graph
            yield break;
        }

        public override void GetNodes (System.Action<GraphNode> action) {
            // This method should call the delegate with all nodes in the graph
        }
    }    
}

It is in a file named SimpleGenerator.cs in the same “Generators” folder as PointGenerator.cs etc. I have tried it in my main Scripts folder with the rest of my project, still doesn’t show up in the Inspector.

I am not using custom assembly definiton files. When SimpleGenerator.cs is in the Generators folder it gets the AstarPathFindingProject.dll assembly, when it’s in with the rest o fmy scripts it gets the standard Assembly-CSharp.dll.

Thanks!

Ok.
Have you enabled any compiler predicates under the Optimization tab or are you targeting WebGL?
In that case you may have to add the graph type manually to the AstarData.cs -> DefaultGraphTypes array as reflection may be disabled for that case.

I am targetting WebGL.

I was able to add my SimpleGraph manually into AstarData->DefaultGraphTypes after putting SimpleGenerator.cs in the Pathfinder namespace (& pathdfinder assembly). It then showed up in the inspector (yay!)

The next problem, though, is making this actually useful. Doing so requires referencing/using stuff from my main project namespace inside the Pathfinder namespace. I need this to either 1) Make my CustomGraph : NavGraph live inside the Pathfinder namespace and do useful things instead of be blank like SimpleGraph : NavGraph, or 2) Add CustomGraph to DefaultGraphTypes while it lives in my project’s namespace.

The obvious is adding a line “using PROJECT_NAMESPACE” along with the other usings, but for some reason I cannot resolve the symbol for PROJECT_NAMESPACE (or any other package namespace) inside the Pathfinding namespace. I’m guessing because Pathfinding stuff uses AstarPathFindingProject.dll while everything else uses Assembly-CStarp.dll?

Sorry to keep asking quesitons that I should probably know the answer to - I have a feeling this is a C#/Unity/Rider problem and nothing to do with your package. I’m an amateur at all this. FWIW, I bought the Pro version via unity, so at least you’re getting something out of this :wink:

Hi

Yeah, unfortunately to reference things outside the pathfinding assembly you have to change the AstarPathfindingProject.asmdef file in the Unity inspector. I think you can configure it to make the outside scripts visible.
See https://docs.unity3d.com/Manual/ScriptCompilationAssemblyDefinitionFiles.html

1 Like

Fwiw it turns out you can configure it to make outside scripts visible, but only outside scripts in other custom assemblies. The default assembly (Assembly-CSharp.dll) is off limits

https://forum.unity.com/threads/add-a-reference-to-assembly-csharp-in-assembly-definition-file.541161/

1 Like