Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Change to Random Spline on End Reached Event
#1
Hi there.  I'm currently working on a 2.5 top down shooter and I'm looking to use Curvy for enemy movement in the game.  I'm trying to setup the following scenario where the enemy chooses a random path once it reaches the end of the current path it's on.  Here's what I've got:

* I've created a couple Curvy splines that I've saved as prefabs.
* I added the spline prefabs to a list of available paths that the enemy can take.
* I wired up a function in code to handle the OnEndReached event using AddListenerOnce.

This all works fine until the OnEndReached event fires.  I set the controller's spline to a new instance of the random prefab I selected, that works... but then Unity hangs for several seconds with several warnings / errors, then continues with the new path.

   

After running it through the debugger in Visual Studio, it appears that I'm stuck in a tight loop of calls to the OnEndReached event... at least I keep stopping at my breakpoint in the method.  I had searched a bit on the forum for something similar and found this post:

https://forum.curvyeditor.com/thread-568.html?highlight=switch

It sounded like I just needed to set the spline on the controller to startup the new path.  I've tried stopping and/or refreshing the path but it does the same thing.  I'm probably doing something goofy as I'm still noobish on using Curvy, but I'm not sure at the moment. Smile  Any thoughts would be appreciated.  Thanks.
Reply
#2
Hi
Is it possible for you to send me a reproduction case? Also, I am assuming you are using Curvy 7.1.4 or higher, am I right?
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#3
(09-11-2021, 11:58 AM)_Aka_ Wrote: Hi
Is it possible for you to send me a reproduction case? Also, I am assuming you are using Curvy 7.1.4 or higher, am I right?

Here you go.  Versions I'm using:

Unity 2021.1.16f1 (also tried in Unity 2020.3.15f2)
Curvy 7.1.5


Attached Files
.zip   CurvyTest.zip (Size: 40.8 KB / Downloads: 1)
Reply
#4
I reproduced the infinite loop when the ship reaches the end of the spline. I will look at this by tomorrow. Will keep you updated.
Have a nice day
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#5
Awesome! Thanks for the help, I appreciate it. Smile
Reply
#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
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#7
Yep, resetting the position did the trick. Thanks very much for the help!
Reply
#8
You are welcome
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#9
What do you think about possibly adding an option to reset the position automatically when the spline for a controller is changed? Smile Would that end up breaking other functionality?
Reply
#10
Hi

Thanks for the suggestion. I believe this is a too specific need for it be one of the parameters of the controllers. To keep things simple, I always try to make available the minimal set of parameters that allows to do all, or at least most, of the possible scenarios.

In other words, if I add a parameter to automatically set the position to 0 when changing the spline, then why not another parameter to reset the Direction parameter when changing the spline? And that's how you end up with too much parameters, making learning how to use controllers complicated, or at least time consuming.

To be honest, I already find some areas of Curvy Splines having too many parameters. Some features for me are superfluous, and lead to extra maintenance work with not much additional value, reducing my time spend in adding more useful features. But unfortunately things were how they are when I acquire Curvy from its previous owner, and it is hard/problematic to remove features after they got released.

But don't let my answer discourage you from suggestion any other improvement you would like to see in Curvy Splines.
Thanks again for your time, and have a nice day
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
Bug Changing spline connection in inspector causes splines to revert to defaults lacota 3 6 03-18-2024, 07:55 PM
Last Post: _Aka_
  GO can't fit end of the spline GameDeveloperek4123 3 13 03-04-2024, 11:06 AM
Last Post: _Aka_
  Avoiding runtime GC allocations on control point position change Ell223 8 18 02-24-2024, 10:43 AM
Last Post: _Aka_
  Keeping a fixed spline length jh092 3 16 02-21-2024, 06:25 AM
Last Post: Primrose44

Forum Jump: