You are trying to create a MonoBehaviour using the 'new' keyword. This is not allowed. MonoBehaviours can only be added using AddComponent(). Alternatively, your script can inherit from ScriptableObject or no base class at all
UnityEngine.MonoBehaviour:.ctor () (at ?)
Pathfinding.Drawing.MonoBehaviourGizmos:.ctor () (at ./Library/PackageCache/com.arongranberg.astar@4.3.61/Drawing/MonoBehaviourGizmos.cs:11)
Pathfinding.VersionedMonoBehaviour:.ctor () (at ./Library/PackageCache/com.arongranberg.astar@4.3.61/PackageTools/VersionedMonoBehaviour.cs:27)
Pathfinding.MonoModifier:.ctor () (at ?)
Pathfinding.FunnelModifier:.ctor () (at ./Library/PackageCache/com.arongranberg.astar@4.3.61/Modifiers/FunnelModifier.cs:60)
ProjectSerpens.Pathfinding.AstarPathHelper:FindPath (UnityEngine.Vector3,UnityEngine.Vector3,Pathfinding.ITraversalProvider) (at Assets/Scripts/Pathfinding/AstarPathHelper.cs:73)
ProjectSerpens.Pathfinding.PathRenderer:Update () (at Assets/Scripts/Pathfinding/PathRenderer.cs:60)
You’re absolutely right
But what’s the right way? I have a central location where I calculate my path (with modifier, traversalprovider) and then use this path to my my character or draw the path with a LineRenderer
You can have a central Seeker component (with attached modifiers). Then you can either use seeker.StartPath or use AstarPath.StartPath combined with a seeker.PostProcess in the OnPathComplete callback to run the modifiers.
Exception: The path has an invalid state. Expected Created found PathQueue
Exception: The path has an invalid state. Expected Created found PathQueue
Exception: The path has an invalid state. Expected Created found Processing
Exception: The path has an invalid state. Expected Created found Processing
Exception: The path has an invalid state. Expected Created found ReturnQueue
Exception: The path has an invalid state. Expected Created found ReturnQueue
After playing around with it and writing a custom movement script, I was wondering how to use my precalculated path with AILerp?
I have a Global Pathfinder GameObject with a Seeker, FunnelModifier and a CustomScript where I calculate the path from the position of a fixed agend to a target:
private Path CalculatePath(Vector3 from, Vector3 to)
{
UnityEngine.Debug.Log("Calculating path from " + from + " to " + to);
var path = GetComponent<Seeker>().StartPath(from, to);
path.BlockUntilCalculated();
return path;
}
Then I set the path to AILerp, added to the agent
var path = CalculatePath(_agent.transform.position, _target.position);
_agent.GetComponent<AILerp>().SetPath(path);
It works, kinda. It seems that the Seeker of the agent now calculates its own path (without a modifier; no added modifier at the agent) and I see 2 path gizmos, one smooth and one angled and the agent follow the path calculated by its own seeker, the given path is ignored.