RemoveGraph giving me an error

AstarPath.active.data.RemoveGraph(AstarPath.active.data.graphs[0]);

gives error:
NullReferenceException: Object reference not set to an instance of an object
Pathfinding.AstarData.RemoveGraph (Pathfinding.NavGraph graph) (at C:/Users/User/Desktop/Lumberjack Mills 2D/Assets/AstarPathfindingProject/Core/AstarData.cs:605)

OK I fixed it but now my issue is that my character gets teleported to another location after the graph is removed. What’s the deal

Can you share any details about your setup? Most helpful would be screenshots of your scene, graph settings, agent settings, and the relevant code for when you call RemoveGraph().

    public static bool Graph1 = true;
    public static bool areaDone = true;
    public int graphMask = 1;
    // Start is called once before the first execution of Update after the MonoBehaviour is created
    void Start()
    {
    }

    // Update is called once per frame
    void Update()
    {
        if (!Graph1 && !areaDone)
        {
            AstarPath.active.data.RemoveGraph(AstarPath.active.data.graphs[0]);
            areaDone = true;
            AstarPath.active.Scan();
        }
    }

Graph1 and areaDone become false when the guy leaves the box area

Ah I see, thanks for the information. Where does your agent move to when the graph is removed? And what’s the expected action, to simply stay where he was before the graph was removed?

he gets teleported to the right inbetween the two graphs

yes, i want him to move normally as if nothing happened in the back-end (no teleporting)

Well if he’s outside the remaining graph when the first graph is removed that could cause issues. Is there a special reason you’re using two graphs in the first place and trying to remove the first?

im just using astar as an alternative to navmesh because it doesnt work for me

Right, but how exactly are you using these two graphs? Why do any get removed? Helps a lot to know about your specific use case :slight_smile:

so the first area has zombies and once it’s cleared, the main guy moves on and cannot go back so I remove the graph there which should activate the graph in the next area which has the boss zombie

You may want to just use a single graph then that spans the entire level, and turn your enemies behavior on or off when needed. So far I’m not seeing any use case here that a single grid graph can’t handle.

ok, i reduced the graphs to 1 but the boss zombie isnt moving even with all the components for ai path
also, my main char is still teleporting when he damages the boss even with the removegraph code gone

I think I need a little more information- what happens when they try to move, do they just never budge? Are they properly getting their destination and a path and just not moving? You can check the Debug information for more info too.

Can you share a video or GIF of this happening?

how do i debug the destination setter? and the boss just doesnt move an inch. he flips towards the main char like i intended but no vector movement

let me work on it for a bit first and if im still stuck ill share a clip

Roger that :+1:

BTW, you can find the debug stuff at the bottom of the AIPath component:
image

how many nodes should my graph have? it’s a pretty big graph

For a Grid Graph without a lot of obstacles you don’t need much density imo. You can get away with just default node size and just make your graph fit the scene and you’ll be good if not great in most cases. I can’t give a single number though as it’s dependent on the size of your play area.

Also your video isn’t playing- or playable at all for some reason. Try uploading it again elsewhere maybe?

it expires in 2 days, here’s another link:

Can you screenshot your agent settings for the ones not moving? Also your graph settings and a scene view too :+1: