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 helps immensely. Thank you.
Available for freelance work—feel free to reach out.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to generate gameobject on the control point Yang Yi 1 6 Yesterday, 10:14 PM
Last Post: _Aka_
  Anomalous connection handling SAMYTHEBIGJUICY 1 3 12-04-2024, 05:08 PM
Last Post: _Aka_
  Getting Distance from a World Point zorksox 3 5 04-16-2024, 07:30 PM
Last Post: _Aka_
  Get position of all control points for a spline gekido 1 9 03-28-2024, 10:08 PM
Last Post: _Aka_

Forum Jump: