10-08-2022, 12:34 AM
Hi there. I'm currently using Curvy 8.2.2 in Unity 2021.3.10f1 for moving my ships in my game. I have a few prefabs of splines, starting with one created in the scene and the others contained in a list of alternate paths on a script. In the script, I check in the ControlPointReached event the control points along the way to determine if I want to switch to a different spline from that location using the SwitchTo method on the spline controller. It works as expected, but I do receive the following error shortly after calling the SwitchTo method:
Here's a snippet of my code that I'm using. From the docs and having a look at the code, SwitchTo looks like it requires the spline controller to be running when doing the switch, which I do have it running. Wondering if I'm missing something on doing the switch correctly? Any thoughts? Thanks for your help.
Code:
NullReferenceException: Object reference not set to an instance of an object
FluffyUnderware.Curvy.CurvySplineSegment.Interpolate (System.Single localF, UnityEngine.Space space) (at Assets/Standard Assets/ToolBuddy/Assets/Curvy/Scripts/Splines/CurvySplineSegment.cs:977)
FluffyUnderware.Curvy.CurvySplineSegment.InterpolateAndGetTangent (System.Single localF, UnityEngine.Vector3& position, UnityEngine.Vector3& tangent, UnityEngine.Space space) (at Assets/Standard Assets/ToolBuddy/Assets/Curvy/Scripts/Splines/CurvySplineSegment.cs:1109)
FluffyUnderware.Curvy.Controllers.SplineController.GetInterpolatedSourcePosition (System.Single tf, UnityEngine.Vector3& interpolatedPosition, UnityEngine.Vector3& tangent, UnityEngine.Vector3& up) (at Assets/Standard Assets/ToolBuddy/Assets/Curvy/Scripts/Controllers/SplineController.cs:488)
FluffyUnderware.Curvy.Controllers.CurvyController.ComputeTargetPositionAndRotation (UnityEngine.Vector3& targetPosition, UnityEngine.Vector3& targetUp, UnityEngine.Vector3& targetForward) (at Assets/Standard Assets/ToolBuddy/Assets/Curvy/Scripts/Controllers/CurvyController.cs:730)
FluffyUnderware.Curvy.Controllers.SplineController.ComputeTargetPositionAndRotation (UnityEngine.Vector3& targetPosition, UnityEngine.Vector3& targetUp, UnityEngine.Vector3& targetForward) (at Assets/Standard Assets/ToolBuddy/Assets/Curvy/Scripts/Controllers/SplineController.cs:593)
FluffyUnderware.Curvy.Controllers.CurvyController.InitializedApplyDeltaTime (System.Single deltaTime) (at Assets/Standard Assets/ToolBuddy/Assets/Curvy/Scripts/Controllers/CurvyController.cs:689)
FluffyUnderware.Curvy.Controllers.SplineController.InitializedApplyDeltaTime (System.Single deltaTime) (at Assets/Standard Assets/ToolBuddy/Assets/Curvy/Scripts/Controllers/SplineController.cs:568)
FluffyUnderware.Curvy.Controllers.CurvyController.ApplyDeltaTime (System.Single deltaTime) (at Assets/Standard Assets/ToolBuddy/Assets/Curvy/Scripts/Controllers/CurvyController.cs:1017)
FluffyUnderware.Curvy.Controllers.CurvyController.Update () (at Assets/Standard Assets/ToolBuddy/Assets/Curvy/Scripts/Controllers/CurvyController.cs:608)
Here's a snippet of my code that I'm using. From the docs and having a look at the code, SwitchTo looks like it requires the spline controller to be running when doing the switch, which I do have it running. Wondering if I'm missing something on doing the switch correctly? Any thoughts? Thanks for your help.
Code:
[SerializeField]
private List<CurvySpline> alternateRoutes;
....
private void ControlPointReached(CurvySplineMoveEventArgs arg0)
{
Debug.Log($"Control Point {arg0.ControlPoint.name} reached.");
if (Random.Range(0, 100) >= 75)
{
if (alternateRoutes.Count > 0)
{
var newPath = alternateRoutes[0];
if (alternateRoutes.Count > 1) newPath = alternateRoutes[Random.Range(0, alternateRoutes.Count)];
var pathInstance = Instantiate<CurvySpline>(newPath);
pathInstance.transform.position = arg0.ControlPoint.transform.position;
_controller.SwitchTo(pathInstance, 0, 1f);
}
}
}