Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Detecting if I'm in a "Connection" control point
#1
Hey,

So I'm making a system where I'm going to use a control point before a connection to initiate some sort of routine that asks if I want to split left/right.  Then once I'm at the last CP, there's a connection there for left or right splines to carry on.

Problem on is I find almost no help in the documentation or videos about this, so I'm essentially reverse engineering the examples.  Oh well, better than nothing I guess.

Here's the code I'm using so far,mostly borrowed from 12-Train:

Code:
   public void OnCPReached (CurvySplineMoveEventArgs e)
   {
       Debug.Log("CP!");

       var mData = e.ControlPoint.GetMetadata<metaTest>();
       if (mData)
       {
           Debug.Log("MD!");
           
           mData.doubleInt();
           cpCount = mData.testInt;
       }

       var connection = e.ControlPoint.Connection.OtherControlPoints(e.ControlPoint)[0];
       if (connection)
       {
           Debug.Log("Connection!");
           //Debug.Log(e.ControlPoint.Connection.OtherControlPoints(e.ControlPoint)[0]);
           //e.Follow(e.ControlPoint.Connection.OtherControlPoints(e.ControlPoint)[0]);
           //SplineController controller = (SplineController)e.Sender;
           //controller.Spline = e.Spline;
           //controller.RelativePosition = e.TF;

       }
   }

Pretty simple, doesn't really do anything yet.  Thing is, for the last chunk it stops everything, and tells me there's a Null Reference Exception:

Code:
NullReferenceException: Object reference not set to an instance of an object
Player.OnCPReached (FluffyUnderware.Curvy.CurvySplineMoveEventArgs e) (at Assets/Player.cs:215)
UnityEngine.Events.InvokableCall`1[FluffyUnderware.Curvy.CurvySplineMoveEventArgs].Invoke (System.Object[] args) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:189)
UnityEngine.Events.InvokableCallList.Invoke (System.Object[] parameters) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:637)
UnityEngine.Events.UnityEventBase.Invoke (System.Object[] parameters) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:773)
UnityEngine.Events.UnityEvent`1[T0].Invoke (.T0 arg0) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent_1.cs:53)
FluffyUnderware.Curvy.Controllers.SplineController.onControlPointReachedEvent (FluffyUnderware.Curvy.CurvySplineMoveEventArgs e) (at Assets/Packages/Curvy/Controllers/SplineController.cs:665)
UnityEngine.Events.InvokableCall`1[FluffyUnderware.Curvy.CurvySplineMoveEventArgs].Invoke (System.Object[] args) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:189)
UnityEngine.Events.InvokableCallList.Invoke (System.Object[] parameters) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:637)
UnityEngine.Events.UnityEventBase.Invoke (System.Object[] parameters) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:773)
UnityEngine.Events.UnityEvent`1[T0].Invoke (.T0 arg0) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent_1.cs:53)
FluffyUnderware.Curvy.CurvySplineBase.OnMoveControlPointReachedEvent (FluffyUnderware.Curvy.CurvySplineMoveEventArgs e) (at Assets/Packages/Curvy/Base/CurvySplineBase.cs:188)
FluffyUnderware.Curvy.CurvySpline.eventAwareMoveDistance (System.Single& tf, System.Int32& direction, Single distance, CurvyClamping clamping, Boolean fastMode) (at Assets/Packages/Curvy/Base/CurvySpline.cs:2744)
FluffyUnderware.Curvy.CurvySpline.MoveByLengthFast (System.Single& tf, System.Int32& direction, Single distance, CurvyClamping clamping) (at Assets/Packages/Curvy/Base/CurvySpline.cs:1193)
FluffyUnderware.Curvy.Controllers.SplineController.Advance (System.Single& tf, System.Int32& direction, MoveModeEnum mode, Single absSpeed, CurvyClamping clamping) (at Assets/Packages/Curvy/Controllers/SplineController.cs:497)
FluffyUnderware.Curvy.CurvyController.Refresh () (at Assets/Packages/Curvy/Base/CurvyController.cs:880)
FluffyUnderware.Curvy.Controllers.SplineController.Refresh () (at Assets/Packages/Curvy/Controllers/SplineController.cs:310)
FluffyUnderware.Curvy.CurvyController.Update () (at Assets/Packages/Curvy/Base/CurvyController.cs:632)

My line of thought is that if I can detect if I'm currently in a Connection node, then I can tell Curvy to go Left/Right based on the players choice.  How do i detect this?

Perhaps there's an even simpler way to go about what I want to achieve?
Reply
#2
If e.ControlPoint.Connection == null, then you are on a control point that is not connected. And your null reference exception is because you don't test if e.ControlPoint.Connection is not null before using it.
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Problems compiling after pulling down project from source control obscurelyme 2 12 02-13-2022, 03:47 PM
Last Post: Marco Schultz
Question Connection Question dazz777 1 112 11-22-2021, 01:42 PM
Last Post: _Aka_
  Allow to control Global Illumination settings in CreateMesh node of PathGenerator RobinB 2 233 11-02-2021, 08:50 AM
Last Post: RobinB
Question Generating a path from selected point to the beginning of spline on a closed spline? Zendariel 5 409 10-29-2021, 01:57 PM
Last Post: _Aka_

Forum Jump: