Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Change to Random Spline on End Reached Event
#6
Hi
The infinite loop is due to the controller still being on the end of the spline when you change its spline, triggering yet another end reached event. What you have to do is to put the controller at the start of the spline when you change its spline:

Code:
    private void PathEndReached(CurvySplineMoveEventArgs arg0)
    {
        _controller.Position = 0;
        SetPath();
    }

Also, when you call Instantiate, the instantiated object does not have its Start called right away. This is the normal behaviour from Unity. To avoid any possible issue, and out of safety, I manually called Start on the instantiated spline. I modified SetPath() as follow:


Code:
    private void SetPath()
    {
        if (attackPaths.Any())
        {
            currentPath = attackPaths[UnityEngine.Random.Range(0, attackPaths.Count - 1)];

            if (currentPath != null)
            {
                _controller.Spline = Instantiate(currentPath);
                _controller.Spline.Start();
            }
        }
    }


I hope this helped
If and when you feel like it, please leave a review for the asset, that helps a lot
Have a nice day
Available for freelance work, feel free to reach out: toolbuddy.net
Please consider leaving a review for Curvy, this helps immensely. Thank you.
Reply


Messages In This Thread
RE: Change to Random Spline on End Reached Event - by _Aka_ - 09-12-2021, 11:00 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Best way to duplicate a spline with an offset Kapistijn 8 1,291 04-12-2026, 03:18 PM
Last Post: _Aka_
Smile Constant speed along a spline? tfishell 1 644 11-13-2025, 11:32 AM
Last Post: _Aka_
  SplineController Ignores Follow-Up and Chooses Wrong Spline Josenildo 7 4,431 07-29-2025, 09:15 PM
Last Post: _Aka_
  Curvy Line Renderer for UI Spline? gekido 7 6,164 07-13-2025, 07:11 PM
Last Post: _Aka_

Forum Jump: