using UnityEngine; using Pathfinding; /// /// Error with Funnel: /// Exception: Unsupported node type or null node /// Pathfinding.Funnel.SplitIntoParts (Pathfinding.Path path) (at Assets/AstarPathfindingProject/Utilities/Funnel.cs:99) /// [RequireComponent(typeof(AstarPath), typeof(Seeker))] public class LinkGraphs : MonoBehaviour { private AstarPath _astarPath; private Seeker _seeker; public Transform ladderTop; public Transform ladderBottom; public Transform pathStart; public Transform pathTarget; private void Awake() { // Cache Components _astarPath = GetComponent(); _seeker = GetComponent(); } void Update () { // Link Ladder if(Input.GetKeyDown(KeyCode.Space)) { AstarPath.active.AddWorkItem(new AstarWorkItem(ctx => { // Modify connections here... var bottomFloor = _astarPath.data.graphs[0].GetNearest(ladderBottom.position).node; var bottomLadder = _astarPath.data.graphs[1].GetNearest(ladderBottom.position).node; var topFloor = _astarPath.data.graphs[0].GetNearest(ladderTop.position).node; var topLadder = _astarPath.data.graphs[1].GetNearest(ladderTop.position).node; Debug.Log("Creating NodeLinks.."); bottomFloor.AddConnection(bottomLadder, (uint)(bottomFloor.position - bottomLadder.position).costMagnitude); bottomLadder.AddConnection(bottomFloor, (uint)(bottomLadder.position - bottomFloor.position).costMagnitude); topFloor.AddConnection(topLadder, (uint)(topFloor.position - topLadder.position).costMagnitude); topLadder.AddConnection(topFloor, (uint)(topLadder.position - topFloor.position).costMagnitude); // Recalculates some meta info regarding which nodes are reachable from which other nodes (these are the colors you see in the scene view) ctx.QueueFloodFill(); })); } // Find Path if (Input.GetKeyDown(KeyCode.P)) _seeker.StartPath(pathStart.position, pathTarget.position); } }