Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error when switching splines
#1
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:

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.  Smile

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);
            }
        }
    }
Reply


Messages In This Thread
Error when switching splines - by ricke - 10-08-2022, 12:34 AM
RE: Error when switching splines - by _Aka_ - 10-08-2022, 07:31 AM
RE: Error when switching splines - by ricke - 10-08-2022, 12:15 PM
RE: Error when switching splines - by _Aka_ - 10-10-2022, 08:46 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  snap to the curve created by the curvy splines segment points ShiroeYamamoto 3 11 04-02-2024, 02:24 PM
Last Post: _Aka_
Bug Changing spline connection in inspector causes splines to revert to defaults lacota 3 6 03-18-2024, 07:55 PM
Last Post: _Aka_
  Using Unity's SplineContainer in Curvy Splines dlees9191 3 15 02-26-2024, 09:49 AM
Last Post: _Aka_
  Distance travelled across multiple splines jh092 1 7 02-23-2024, 09:44 AM
Last Post: _Aka_

Forum Jump: