UpdateGraphs with collider bounds (bridge) is dodgy

Hey there,

I implemented bridges into my project by doing so:

if (use2D) {
	switch (type) {
	case ColliderType.Capsule:
	case ColliderType.Sphere:
		Collider2D cCol = Physics2D.OverlapCircle(position, finalRadius, mask);
		if (cCol == null) {
			return true;
		} else if (cCol.gameObject.tag == "bridge") {
			return true;
		} else {
			return false;
		}
	default:
		Collider2D pCol = Physics2D.OverlapPoint(position, mask);
		if (pCol == null) {
			return true;
		} else if (pCol.gameObject.tag == "bridge") {
			return true;
		} else {
			return false;
		}
	}
}

Inside AstarPathfindingProject>Generators>Base around line 530 in the Check() function, which checks to see if there is an obstacle at each node position.

The bridges have colliders on them. When the bridges are built, they issue the AstarPath.active.UpdateGraphs() command with their collider bounds.

This works… sometimes. Other times, it works partially or not at all. I see no reason why this would be inconsistent like this, and I was hoping someone could point me in the right direction to get this working 100% of the time.

As you can see in the image (gray lines: bridges, red outlines: areas where nodes were improperly marked as unwalkable)

Hi

I’m not quite sure how your scene is configured, but it looks like you may have multiple colliders that overlap, is that right? In that case the OverlapPoint and OverlapCircle calls may return any one of those overlapping colliders and if they have the same z coordinate would just be up to chance if you got the bridge or the underlying collider. Do you think this might be the case here?

The Unity documentation states

If more than one collider overlaps the point then the one returned will be the one with the lowest Z coordinate value. Null is returned if there are no colliders over the point.

1 Like

Thanks for the quick reply Aron!

I do.

It may be the case. I’m currently drawing at straws as to what is causing it, as it seems particularly random.

I read that and I’ve tried setting the bridge’s transform.z value both higher and lower with seemingly no effect, among several other things. However, I didn’t try the collider’s center property. I don’t know if that would have any special effect. It was my understanding that that is just a local offset value. I mention that, rather than giving it a go, because I’m currently heading to bed for the night. I’ll give that a shot in the morning if you or others don’t say it wouldn’t make a difference.

Okay. I don’t think the center offset should matter.

Does it work if you scan the graph manually from the inspector?
It is possible that you need to call Physics2D.SyncTransforms() before the graph update (after you create your bridge). The physics engine data might not be up to date when the graphs are updated. If this is necessary then it’s a bug in this package. The graph updates should be calling this automatically.

1 Like

Hey Aron!

I went back and double-checked the collider z-value solution, and I found the issue! It didn’t work the first time because I had forgotten that my bridge transform gets reset to match the mouse position, with the z-value getting clamped to 0. I set it to -1 and it works perfectly!

My apologies. I wish I’d remembered that the first time around.

Thanks for bringing that solution back under my radar :smiley:

1 Like