简体   繁体   中英

Trail Renderer doesnt work properly when timeScale is set to 0

I want to use TrailRenderer when my game is paused, but since timeScale is 0 the resulting deltaTime is 0. This caused TrailRenderer to not function (the tail never dies).

I didn't find any parameter to be able to manually set the update duration or call update of TrailRenderer.

Like in an Animator we have the option to make it update in "UnscaledDeltaTime", how can i do it for a TrailRenderer?

After a little bit of research, it doesn't seem like you can do this. You can do a few things here, but none of it will be as easy as just setting the time scale on the renderer.

Maybe think about how you are pausing the game and see if the timeScale really is your best solution.

This question came up here as well How to make TrailRenderer work when timeScale is 0 in Unity? .

This seems to indicate that it cannot be done.

There's a value for Time.unscaledDeltaTime that you could use.

There is a post on the Unity forums describing a similar peculiarity with Time.unscaledTime and Time.realtimeSinceStartup . The OP states what they're using at the bottom of the post:

float lastFrameRealtimeSinceStartup;
float unscaledTimeWhilePlaying;

void Update() {

   float dRealtime = Time.realtimeSinceStartup - lastFrameRealtimeSinceStartup;
   if (dRealtime > (1.0f / 20.0f)) {
       //Assume the high dTime is due to the game being paused or lost focus
       dRealtime = 1.0f / 20.0f; //Set it to a reasonable time (20 FPS)
    }
    unscaledTimeWhilePlaying += dRealtime;
    lastFrameRealtimeSinceStartup = Time.realtimeSinceStartup;

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM