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
  Move with constant velocity in Relative mode athos_k 3 616 07-21-2020, 11:39 AM
Last Post: _Aka_
  Move CP00X position in hierarchy UsernameHed 1 1,047 11-12-2019, 02:01 PM
Last Post: _Aka_
  Move the Create Mesh of a CurvyGenerator Out of the Main Parent UsernameHed 3 2,157 07-08-2019, 06:57 PM
Last Post: _Aka_
  Spline events not working in IL2CPP build (Android) callen_mrez 6 3,688 06-04-2019, 09:24 PM
Last Post: _Aka_

Forum Jump: