I’m trying to prevent the AstarPath component from including prizes’ colliders (coins, powerups, the usual) when it creates the Grid Graph. These gameObjects need to have colliders so they can be picked up.
In one less sophisticated pathfinding-component there was an option to list tags as well. Any gameObject that had any of the tags in the list was excluded just as if it didn’t have a collider at all.
Isn’t that kind the exact opposite of the penalty-tags?
Anyhow. I’m waiting here to slap my forehead (hard) when/if someone out there kindly bothers to point out that "excluding collider-containing gameObjects from the graph scan is simply done by… ". (slap).
I realize that deactivating the coins etc. for the duration of the scan and reactivating them after the scan would likely work.
It would just be a bit more easier to not to have to instantiate the coins, deactivate them and keep them in a List and check in some script some scanInitiated-bool and AstarPath.active.isScanning (I guess…) and then activate the goodies.
My humble thanks to anyone who bothers to offer a solution.
I put all the goodies in a goodie-specific layer. Then chose that layer in the “Mask”-setting. IIRC the result was that everything in the scene became unwalkable - every node had that red cube.
Anyway using the “Mask” doesn’t work in my case because I need several layers because of other components and the “Mask”-setting is meant for selecting only one layer.
I eventually ended up doing the deactivate/activate-thing I speculated. Curiously enough the isScanning-bool means that the scanning is in progress but not completed. Thus polling it didn’t help.
The next attempt was of course to go into the source of the Scan()-method and add my own bool to the class and updating it in places I thought were correct. No joy.
Thus now I’m simply waiting 500 milliseconds from the beginning of the scan until I instantiate the goodies. The inelegance of this solution boggles the mind
Layer masks can contain multiple layers, you can make any subset of all layers included in the scan. The mask lists layers that are included in the scan, not excluded.
If you want to get a callback when the scanning has completed you can use:
`AstarPath.OnLatePostScan += DoStuff;
public void DoStuff ( AstarPath astar ) {
AstarPath.OnLatePostScan -= DoStuff;
Debug.Log (“Right after scanning has completed”);
}
`
However it might be easier to disable A* Inspector -> Settings -> Scan On Awake and then you can invoke scan whenever you want.
I tried the …OnLatePostScan+=… delegate but for some reason it never got called. By the way. I’m still evaluating the free version to see if your asset meets my needs so perhaps it’s because of that.
The ‘Scan on Awake’ combined with putting obstacles in a obstacle-specific layer sounds actually a brilliant idea!
I’ll try that and retire the 500 msec hack without anyone ever having heard of it …