Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Activate Curvy Generator After Scene Load
#1
I'm using Curvy generators for a project to simulate wires during a virtual assembly of a robot. It works great during the initial assembly scene, but I have an issue where the generator stops updating for a time after switching scenes (the robot including the wires use Object.DontDestroyOnLoad to carry over between scenes). In my project the user can switch scenes to test their assembled robot in a trial scenario and then switch back to the assembly scene to make adjustments. When they return to the assembly scene, they should be able to click and drag the connectors to re-connect the wires differently, but currently the Curvy Generators are all stuck after re-loading the scene and I can't figure out how to get them to start updating again. They do seem to start working again on their own sometimes, but it usually takes several minutes. Is there something I need to do to re-initialize or otherwise force the generators to start updating again after the scene loads?
Reply
#2
Hi
I was never confronted to you use case, so if you can send me a simplified reproduction case, that would help me investigate the issue.
Until then, the only things that I can say are probably not that helpful:
  • Check the CurvyGenerator.IsInitialized property
  • Check the CurvySpline.IsInitialized property
  • Manually call the CurvyGenerator and CurvySpline Refresh method
  • Make sure the CurvyGenerator's AutoRefresh and RefreshDelay have valid values.
  • Try to wait for a couple of frames after the scene switching before doing the things above.
I hope this helped
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
(04-30-2021, 08:18 AM)_Aka_ Wrote: Hi
I was never confronted to you use case, so if you can send me a simplified reproduction case, that would help me investigate the issue.
Until then, the only things that I can say are probably not that helpful:
  • Check the CurvyGenerator.IsInitialized property
  • Check the CurvySpline.IsInitialized property
  • Manually call the CurvyGenerator and CurvySpline Refresh method
  • Make sure the CurvyGenerator's AutoRefresh and RefreshDelay have valid values.
  • Try to wait for a couple of frames after the scene switching before doing the things above.
I hope this helped

Unfortunately manually refreshing the generator and splines doesn't seem to make much difference, even if I delay a second or two after the scene load. The generator and splines all report that they are initialized and the AutoRefresh and RefreshDelay values seem valid immediately after the scene load. I created a simple project to demonstrate the issue, which I will send you a link to in a private message. In this simpler scene, the generator starts working again somewhere between 5 and 30 seconds after a scene change. In my actual project the delay is sometimes a couple minutes.

Update: I found that calling CurvyGenerator's Refresh every frame does work as desired, so I guess in my case it's just the AutoRefresh that isn't working correctly immediately after the scene load. As long as there's not too much of a performance penalty this should be a reasonable workaround for me.

Thanks
Reply
#4
Hi
I will take a deeper look at all this soon.
About the Refresh method, when called while there is nothing to process, the method returns without doing much, so it should not impact performance. So for now it is a good workaround. I will take a look at your project ASAP to find the cause behind the unwanted behavior.
Thanks 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
#5
Hi
I have some news: I found the cause of the issue. Basically, the AutoRefresh feature (and its parameter Refresh Delay) relay on a stored timestamp. Since you don't destroy the CG when switching scene, that timestamp remains, while the time of the scene is reset to 0. So when you switch scene at second 37, you have to wait 37 seconds in that new scene before the generator updates again. I will fix this very soon. Will keep you updated.
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
Here is the fix: Replace the content of CurvyGenerator.TryAutoRefresh with this:
Code:
        public void TryAutoRefresh()
        {
            if (AutoRefresh)
            {
                double realtimeSinceStartup =
#if UNITY_2020_2_OR_NEWER
                    Time.realtimeSinceStartupAsDouble;
#else
                    Time.realtimeSinceStartup;
#endif
                if (Application.isPlaying)
                {
                    if (realtimeSinceStartup - mLastUpdateTime > RefreshDelay * 0.001f)
                    {
                        mLastUpdateTime = realtimeSinceStartup;
                        Refresh();
                    }
                }
#if UNITY_EDITOR
                else
                {
                    if (realtimeSinceStartup - mLastEditorUpdateTime > RefreshDelayEditor * 0.001f)
                    {
                        mLastEditorUpdateTime = realtimeSinceStartup;
                        Refresh();
                    }
                }
#endif
            }
        }
Please let me know if this worked for you
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
I removed the manual refresh workaround and replaced the TryAutoRefresh code as you said and it's working perfectly now. Thanks!
Reply
#8
Good news, glad to read that. Let me know if you have any other problem.
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


Possibly Related Threads…
Thread Author Replies Views Last Post
  Spot Generator resetting some values after Script compilation Mos Def 2 21 4 hours ago
Last Post: Mos Def
  Compilation issues for iOS with a scene containing generators puzzlekings 2 25 05-13-2021, 06:53 PM
Last Post: _Aka_
  Reference the materials used in generator boriskourt 5 108 05-09-2021, 09:32 PM
Last Post: _Aka_
  How to change the mesh inside the generator elitegorgong 5 353 04-03-2021, 04:53 PM
Last Post: _Aka_

Forum Jump: