Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Disable the Update of the CurvySpline
#1
Hello,

I have some profiler spikes from the CurvySpline.Update() in play mode.
(I have checked CheckTransform to false).

But I haven't found any Update methode in the CurvySpline, weird ?


When I am in play mode, I would like to set the script CurvySpline to disabled. But when I do that, my SplineController stop to move along the path. Why ? A Spline, When calculated, is just datas stored, no need to do an update for the Spline, right ?


I don't want any new change in the Spline when I am in build. I just want SplineController moving along this Spline.





EDIT: oh, I found out the script CurvySPline_private, and I found yours function Update, FixedUpdate and LateUpdate.
So at each frame, unity goes in the Update, FixedUpdate and LateUpdate methode (even if it doen't go in your the doUpdate function).
I would like to disable the script CurvySpline completly, but still be able to move along this spline with the SplineController. Is it possible ?

I Have managed to add in the enum a None Property:

Code:
public enum CurvyUpdateMethod
   {
       Update,
       LateUpdate,
       FixedUpdate,
       None
   }

And then it works, in the CurvySpline_private, we don't go into your Update method.

I guess it's resolved Smile, I suggest you to add this None to this enum
Reply
#2
Hi,
Even though you avoided the spikes, I am curious to know what caused them. Can you please either send me a scene with the issue, or send me the result of your deep profiling? In both cases, what version of Curvy are you using?
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
Photo 
[Image: IEuqaNYBpIe_Update.PNG]
[Image: IEuqnBGekWe_CurvyController.PNG]

Here SplineController Update take 0.53ms, wich is enormous for only one call.

There are a LOT of if(), switch statement every frame in the function InitializedApplyDeltaTime, ComputeTargetPositionAndRotation for exemple
A Simple InterpolateFast(percent + speed) wouldn't be more efficient ?
An optimise SplineController from a static spline should just pick a value in an array of precalculated point. (2 value, an Vector3 and a Quaternion) I don't know if it's the case, and how to have a faster SplineController.
Reply
#4
I Used my own CustomSplineController


here is the code:

Code:
    private CurvySpline _curvySpline = default;
    private float _speed = 0.0120f;

    public void CustomUpdate()
    {
       _currentPercent = (_currentPercent + (_speed * Time.deltaTime));
       if (_currentPercent >= 1)
       {
           _currentPercent %= 1;
       }
       _toMove.position = _curvySpline.InterpolateFast(_currentPercent);
       _toMove.rotation = _curvySpline.GetOrientationFast(_currentPercent);
   }

I have 200 of this controllers. Each of them are called at each update by a script who contain an array of the 200 players.

I have profiled 200 of your SplineController, and my CustomSplineController, the result (in build):
200 of your SplineController use 50% of the CPU, and 14.5ms
Then I have tryed with my custom script:
200 of my CustomSplineController use 9,4% CPU, for 1.51ms

I think you could have in your plugin a custom optimised script like mine.

Then only problem for me: I use InterpolateFast (or Interpolate), and the speed of my object depends of the lenght of the segment there are in. How could I change that ?
I have also tryed that: 
Code:
_toMove.position = _curvySpline.MoveByLengthFast(ref _currentPercent, ref direction, _speed * Time.deltaTime, CurvyClamping.Loop);
(or other move function, but it always the same)

Thanks you again for everything.
Reply
#5
Hi,
Updating the controller can be just an update of the position with simple maths, but the current implementation is not that simple to be able to handle triggering events and connections handling, both of which can change the direction, speed, etc... of a controller in the middle of the update.
But this does not mean that the current controller code can't be optimized while still handling connections and events. That's why I am curious about your use case. If you can send me either the profiling data completely expended, so I can so what happens after the ApplyDeltaTime call, or a scene with those performances, it would help optimize the slow parts.

For your custom solution, use InterpolateByDistanceFast instead of InterpolateFast (valid values between 0 and spline.Length)
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#6
Thanks you again for your answer about INterpolateByDistance, it works Smile

For my usecase: there were several thinks I didn't do right for my mobile build:
- I was activating and desactivating objects with your Spline inside (the Spline.OnEnable() was apearing in the profiler). My solution for that: I just active the Spline at start, and let it like that, with the UpdateIn: None.
- 200 of yours SplineController every Update is too much. Because: 
200 object with Update() inside is bad for unity, because it's mean 200 different calls to C++ to C#. With one only Update(), who call 200 custom function, it's way better for mobile application. (so it's not your plugin, but my specific usecase).

Try to put 200 of your SplineController moving aloing a very long SPline (more than 3000 of lengh), and build with the profiler connected to the android phone (a bad android phone if possible^^). With a Profiler.BeginSample("SplineController Update"), Profiler.EndSample() between the update methode of the SplineController.

I know you have a lot of trigger & option to manage for everyone. Options I don't realy need. But with your code I have managed to create customs script who are doing just what I need. I have managed to have 60 fps with more than 200 custom SplineController, with position, rotation and offset, it's way enought for me.

And sorry for bothering you so much with everything ahah, i'm trying to first search into your documentation & the code before asking you something.

(for exemple, I discovers the Abstract class in C#, I was searching for your Update() method in the CurvySpline.cs, And I took 1 hour to find your CurvySpline_private, and unnderstanding what it was ahah x))
Reply
#7
Splines rely on some internal cached data to work properly. This cache is updated whenever a relevant change to the spline happens. When the spline is disabled, the code stops monitoring those changes. So when it is enabled again, the call rebuilds the cache. That's why it is extensive.

No worries about bothering me. All I ask for is that the users try to find the answer first by searching on their side inside all the provided information, which you already do, so it's ok.

You spoke about abstract classes. I think you mixed it with partial classes. CurvySpline is not an abstract class, but I do indeed use abstract classes in Curvy, like CurvyController. Here is the list of key words in C#
https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/
By consulting it right now, I learned that not only classes can be partial, but methods too. That was thanks to you Smile
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#8
I am curious if I need to make this modification.

I am mostly using Curvy to place trees in gardens along a path for an arch vis project, just to name one use example. These trees will not move at all during run time.

Would having a NONE option in update help with performance?
There's going to be a lot of objects placed so every little bit helps.

Thank you kindly.
Reply
#9
Hi,

Since the objects do not move, I suppose you either called controller.Stop() or set controller.Speed to 0. In both cases, there is no significant computations done, so the None option will not help much. But as always when asked about performance issues, you really should profile your game first, and check that the controller's updating code is really an issue, and only then try to optimize the controller's code.

If you have a lot of objects to place, you might want to use the Volume Spots CG module instead of controllers. Here is its documentation, and you can see examples of its usage in multiple example scenes, like 22_CGClonePrefabs.
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
  Disable rebuild of meshes in dynamic mode Zilk1 1 8 10-04-2023, 09:50 AM
Last Post: _Aka_
  Disable Generator Rasterized Objects SAMYTHEBIGJUICY 3 5 09-01-2023, 03:38 PM
Last Post: _Aka_
  I have a question about curvySpline haifeng.huang 12 32 07-14-2023, 09:34 AM
Last Post: _Aka_
  "Deadloop in CurvySPline.Refresh" spam Valkymaera 3 11 05-30-2023, 10:56 AM
Last Post: _Aka_

Forum Jump: