Exception thrown (and also sometimes crash) when reloading scene

Hello again!

I’ve run into another weird issue. This has been happening when trying to reload a scene, which has an A* GridGraph, with a bunch of of characters moving. Every time i reload the level… sometimes, though not always, this error comes up.

Exception: Trying to initialize a node when it is not safe to initialize any nodes. Must be done during a graph update

This of course, breaks everything. If I have enough seekers in the map, it can even crash Unity when attempting to reload the scene (I can grab the exception using the Mono debugger though, so I still believe it has something to do with this).

I don’t know how to fix this (this is even more strange, because I’m using a system which used an older version of the A* Pathfinding project, and never had issues like this).

Maybe its because I need to do some special cleanup or initialization that wasn’t required before, I’m not sure.

Here’s a stack trace of the problem

`Exception: Trying to initialize a node when it is not safe to initialize any nodes. Must be done during a graph update
AstarPath.InitializeNode (Pathfinding.GraphNode node) (at Assets/AstarPathfindingProject/Core/AstarPath.cs:1676)
Pathfinding.GraphNode..ctor (.AstarPath astar) (at Assets/AstarPathfindingProject/Core/Nodes/GraphNode.cs:54)
Pathfinding.GridNode..ctor (.AstarPath astar)
Pathfinding.GridGraph.ScanInternal (.OnScanStatus statusCallback) (at Assets/AstarPathfindingProject/Generators/GridGenerator.cs:783)
AstarPath.ScanLoop (.OnScanStatus statusCallback) (at Assets/AstarPathfindingProject/Core/AstarPath.cs:1865)
AstarPath.Scan () (at Assets/AstarPathfindingProject/Core/AstarPath.cs:1782)
AstarPath.Awake () (at Assets/AstarPathfindingProject/Core/AstarPath.cs:1311)
`

Anything that can help would be greatly appreciated.

Thanks a lot,
Italo F. Capasso B.

Ok, found and answer! It seems that I had for some odd reason some A* Pathfinding script in the Execution order setting., These were all jumbled (no idea why, probably me experimenting vefore). But removing them seemed to solve the iissue n_n.

Huh, weird stacktrace. I cannot see how that could happen when called in that order…

Well, anyway, the issue was solved. Do you remember what execution order settings could replicate this issue?

I am getting exactly the same issue, except the above fix does not apply, as I do not have any A* related scripts in the execution order…

The scene only has one agent navigating on a grid graph, and the issue, as above, happens sporadically when restarting the level, that is, calling:

       <i> Application.LoadLevel(Application.loadedLevelName);</i>

Is there some clean up that I should be performing?

Following is the stack trace:

Exception: Trying to initialize a node when it is not safe to initialize any nodes. Must be done during a graph update AstarPath.InitializeNode (Pathfinding.GraphNode node) (at Assets/AstarPathfindingProject/Core/AstarPath.cs:1625) Pathfinding.GraphNode..ctor (.AstarPath astar) (at Assets/AstarPathfindingProject/Core/Nodes/GraphNode.cs:52) Pathfinding.GridNode..ctor (.AstarPath astar) Pathfinding.GridGraph.ScanInternal (.OnScanStatus statusCallback) (at Assets/AstarPathfindingProject/Generators/GridGenerator.cs:685) AstarPath.ScanLoop (.OnScanStatus statusCallback) (at Assets/AstarPathfindingProject/Core/AstarPath.cs:1808) AstarPath.Scan () (at Assets/AstarPathfindingProject/Core/AstarPath.cs:1725) AstarPath.Awake () (at Assets/AstarPathfindingProject/Core/AstarPath.cs:1271)

Please let me know if I can provide any more information that can help.
As Edwood mentioned, this is a game breaking bug…

Thanks for your time

And I am using the latest version, 3.4.0.5

I just got this exact one today also. when loading a level

Hi

Sorry for the really late answer, I have been away for a while and haven’t been able to answer many questions in the forum.

Does any one of you have a small example project which you could zip up so I could have a look at it? It will be really hard for me to debug it using only stacktraces.

I have got the same problem. It is sporadic, it never happened to me but to some of our tester. For some people it is often.
It happens to the same persons usually.

I have got AStarPath in execution order, but it is at the top of execution chain.

Is there a way I can clean up AStarPath, I Could do it as the first thing when loading scene. So AstarPath have got clean start it might be that there are some data from previous AStarPath scene. It never happened first time AStarPath was used.

We are close to release and it is kind of hot problem for me.

Exception: Trying to initialize a node when it is not safe to initialize any nodes. Must be done during a graph update
  at AstarPath.InitializeNode (Pathfinding.GraphNode node) [0x00000] in <filename unknown>:0 

  at Pathfinding.GraphNode..ctor (.AstarPath astar) [0x00000] in <filename unknown>:0 

  at Pathfinding.GridNode..ctor (.AstarPath astar) [0x00000] in <filename unknown>:0 

  at Pathfinding.GridGraph.ScanInternal (.OnScanStatus statusCallback) [0x00000] in <filename unknown>:0 

  at AstarPath.ScanLoop (.OnScanStatus statusCallback) [0x00000] in <filename unknown>:0 

  at AstarPath.Scan () [0x00000] in <filename unknown>:0 

  at AstarPath.Awake () [0x00000] in <filename unknown>:0

Hi

Ok, that looks like a bug.
Are you sure the previous AstarPath instance has been properly destroyed before loading the new one? (It should not make a difference, but it is kind of an edge case, so that might be where the bug is).
Can you replicate this issue (or your tester)? If yes, then maybe we could add some debugging code to figure out what is going on.
Are you doing any updates to the graph?
If you are using multithreading, try turning it off (this feels like it might be related to multithreading).

I don’t know if it was properly destroyed. I load a new scene and I expect that it will work.
I assume we do not have to do anything manually like calling some destroy function explicitly ?
Some of our tester states that he got this problem every time his computer goes out of hibernate state.

Yes I’m doing updates to the graph.
I will test Thread count set to none, and see what our tester will say.

Version I’m using is 3.5.2 we bought AStarPath some time ago but we decided to stay with free version for now.

Just got some info from our tester he said that it works fine without threading. There was no exception.

Sorry for bumping.
But I would like to know if we can expect some solution.

We are releasing in a few weeks and we cannot do it without threading, it’s just to slow.

Hi

Would it be possible for you to share your project with me (or just some example scene where you have replicated the bug)?
I have never been able to trigger it, and I have unit tests which reloads scenes at least 20 times.

And I assume you do not use additive loading?

No, you should not have to do that.

3.5.2 is pretty old however (2.5 years I think). I have done some extensive rewrites of the internal handling of the path queue and multithreading since then. Maybe you should try upgrading to a more recent version?

What is the latest version compatible with Unity 4. And where can I get it ?

To be more precise right now we are using Unity 4.6.3
We have been developing our game for 4 years and we just cannot move to Unity 5 now.

Hi

See Need an A* Pathfinding Project Free version for Unity 4.6.3