SpeedTree on terrain, ignored by A*?

At least on my tests it seems like generated SpeedTrees that are part of the terrain are not detected by the collider when building my graph, regardless of them being on the ground layer or on default layer. If I take a speedtree and drag it to the scene, then it is detected. Is this not supported by A*?

What I find odd is that A* can detect ground elevations that block the collider just fine, so it’s beyond me why speedtrees shouldn’t be working fine, regardless of what layer they’re on.

Expanding upon my post, here is a screenshot of the problem:

The tree to the left was dragged to editor as a prefab. Both it and the white capsule are on default layer and perfectly detected by the graph generator.

However the tree to the right is not being detected. It’s also on default layer thanks to the new terrain property “Preserve Tree Prototype Layers”. This really works, trees are on “default” layer as is proven by hiding the default layer, makes all trees disappear.

So, is there any reason why A* is raycasting through that terrain speedtree and ignoring it when drawing a graph?

Hi

I think this is a unity quirk/bug. If I remember correctly the Unity terrain system doesn’t generate tree colliders while in editor mode for some reason. I think it will pick them up if you scan the graph once the game is playing, could you try that?

It worked, thanks!

So this means I have to save the graph and reload it, or scan it after opening a scene. A pity, but at least it is working :wink:

Hi

Usually graphs are scanned when the game starts (that’s the default setting), would that work for you? The downside would just be that you couldn’t see the result in the editor mode.

Otherwise an easy solution is to generate the cache for cached startup (under the save and load tab) when you have started the game.

Ah, I didn’t know it recalculated on start! When does this exactly happen, as a scene is loaded?

The only catch is not being able to check walkability on editor, but it’s a minor issue compared to what I had yesterday!

It happens during the Awake call on the AstarPath component. You can disable this under A* Inspector -> Settings -> Scan On Awake.
if you do so you will have to scan the graphs manually instead using

AstarPath.active.Scan();

One thing to note (which I learned through trial and error) is that AStarPath.active.Scan() will wipe out any custom connections made through AddConnection(), or node Walkability flags that may have been set during gameplay!

It really is meant as a “wipe clean” function, and should probably only be used when loading a level from a “stock” state.

1 Like

Yes, the Scan function recalculates the graphs from scratch, throwing away everything that may have been there before.

I know this is a very old thread, but it’s all that I found when looking for speedtree detection on terrains using A*.

I’m having the same issue as the OP, with terrain trees using speedtree not detected by A*, except that even when I scan in play mode, it still doesn’t detect the trees. If I just drag the trees in as prefabs they work fine as well.

This is on Unity 2021.3.17, so I’m guessing something changed in Unity since the original thread. Is there anything I can do to have A* correctly detect my speedtrees on the terrain?

Edit: It works on the 4.3.61 beta but not on the 4.2.18 stable version. So I guess I’ll have to use the Beta.

1 Like