Tower Defence - Check Pathing

Apperently. There was one difference between the two responsible. The Tag wasn’t the same. Thing is, I can’t figure out where the tag is set in A*, Seeker, or Lerp.


This method is supposed to check if the position is valid for tower placement.
Specifically, make sure that it doesn’t overlap another tower, and that all creeps, the start, and the end, are all accessable from one another.

I have an extra gameobject, the PathingChecker, which has pathing identical to a tower, which is moved to the position, used to check for collision, then moved back outside the game area.
It works in some cases, but not others. You can place directly on the start or end point, which should be blocked because it would make those points not conencted to the rest. Also, sometimes you can make a full wall (but not always) which entirely blocks off the path, and it is not detected. After placement, the graph updates again, and it turns out to be a full block.

I would prefer not instantiating a tower then destroying it instantly if I can avoid it.

public bool validatePlacement(Vector3 iPosition)
{
    
            SpriteRenderer sprite = PlacementPrototype.GetComponent<SpriteRenderer>();
    PathingChecker.transform.position = new Vector3(iPosition.x, iPosition.y, iPosition.z);

    // Check all Unit positions for collision.

    var guo = new GraphUpdateObject(PathingChecker.GetComponent<Collider>().bounds);

    foreach (Unit unit in EntityManager.GetTowers())
    {
        Bounds bounds = unit.gameObject.GetComponent<Collider>().bounds;
        if (PathingChecker.GetComponent<Collider>().bounds.Intersects(bounds))
        {
            
            sprite.material.SetColor("_Color", new Color(1, 0, 0, 0.5f));
            PathingChecker.transform.position = OutOfTheWay;
            return false;
        }
    }

    // Make sure all creeps can get to the goal.


    List<GraphNode> nodes = new List<GraphNode>();

    nodes.Add(spawnPoint);
    nodes.Add(goalPoint);

    foreach (Creep creep in EntityManager.GetCreeps())
    {
        nodes.Add(AstarPath.active.GetNearest(creep.transform.position).node);
    }

    if (!GraphUpdateUtilities.UpdateGraphsNoBlock(guo, nodes, true))
    {
            sprite.material.SetColor("_Color", new Color(0, 1, 0, 0.5f));
        PathingChecker.transform.position = OutOfTheWay;
        return false;
    }
    
            sprite.material.SetColor("_Color", new Color(0, 0, 1, 0.5f));
    PathingChecker.transform.position = OutOfTheWay;
    return true;

}