Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Solved] API Move() and Events example
#1
I want to use the API command Move() and get a callback through the Event-System.
This is useful to get a function call in side the current script while Move() reaches a ControlPoint.

If any SplineController runs over the Spline.ControllPoint then nControlPointReachedEvent() is triggered well.
You can determine the SC in e.Sender for sure (see Default Curvy Events Handler.cs)

But unfortunately I get no fire while Move() runs over a CP.
Perhaps I use Move(tf, dir, fdist, clamp) in a wrong way?


Code:
public class PassiveFollower : MonoBehaviour {
   public CurvySpline Spline;
   public float aDist;
   public float tf = 0;
   public int dir = 1;
   public Vector3 posfollow;

   IEnumerator Start() {
       // Wait until the spline is initialized
       if (Spline) {
           while (!Spline.IsInitialized)
               yield return null;
       }
       // Add EventTrigger to the current Spline
       Spline.OnMoveControlPointReached.AddListenerOnce(onControlPointReachedEvent);
   }
   void Update() {
       aDist += 0.01f;
       tf = Spline.DistanceToTF(aDist);
       posfollow = Spline.Move(ref tf, ref dir, 0.01, CurvyClamping.Clamp) + Spline.transform.position;
       transform.position = posfollow;
  }
   void onControlPointReachedEvent(CurvySplineMoveEventArgs e) {
       //Gets triggered by a SplineCOntroller but not by Move();
       Debug.Log("onControlPointReachedEvent");
   }
}
(Henry Ford) Each hour more of searching is each hour less of your live time.

Reply
#2
Tried your script and it's working. So it must be a matter of versions. I tried it with 2.0.4 and the latest dev repo. So you're perhaps using an older, intermediate dev version, I remember that I fixed the GC alloc issue one day and another related issue two days later. The latter problem was that runtime event binding wasn't recognized - this would explain your problem exactly.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Player move with object mcarman 4 8 07-29-2024, 06:49 PM
Last Post: mcarman
  Raise spline events during edit mode arcadeperfect 3 10 08-24-2023, 08:38 AM
Last Post: _Aka_
Thumbs Up Assembly Definitions (Solved) lacota 3 6 06-01-2023, 11:04 AM
Last Post: _Aka_
  Can you move generated objects along spline? FernDigestive 1 8 04-02-2023, 12:14 PM
Last Post: _Aka_

Forum Jump: