Royal Run jittery chunks

I’m early on in the Royal Run part of the new unity 6 3D course and I noticed during the chunk removal, the chunk platform the player is located on /the one closest to the camera, in front of the one that gets removed, there is a tiny shift on the Z-axis.
I couldn’t work it out, ended up copying the tutorial source file from the Commit on Gitlab…AND IT STILL DOES IT.
If you watch the platform closely, it shifts every time the chunk behind it is removed.
If i comment out the Remove(chunk) line - it doesn’t do it anymore. If i change the if statement so that it removes chunks further back, it still does it, just further back out of camera view. It only slightly moves ONE chunk in front of the one that is being removed!
any ideas?

In the video, I’ve set the chunk length longer to see the gap between the chunks and the shift is more visible. It still happens when the chunkLength is 10f as the tutorial says.

Hu urbanvanilla,

Welcome to our community! :slight_smile:

I’ve watched your video twice but I wasn’t able to see what you mean. Could you point me to the exact time stamp where it happens? And am I supposed to see the issue in the Scene window or in the Game window?

Have you already tried to add Debug.Logs to your code to see what is going on during runtime? Or checked the Inspector to see if a position unexpectedly changes?

Also try to pause the game a moment before the shift usually happens. Keep the Inspector of the concerning game object open. Then click the third button next to the Pause/Play button to flip through the subsequent frames. This way, you’ll hopefully see the exact moment when the problem occurs.

Hi Nina,
it’s really really quick, but at around 9-10 seconds when I zoom in on the Scene window, you can see the platform that the running model is positioned on will shift forwards just ever so slightly. It does this every time the platform chunk behind it gets destroyed/Removed from the chunk List. It is evident in both Game and Scene windows, but its more obvious when I zoom in from the Scene angle. I will try and do a step through and watch the Transform values, but basically the only thing I’ve gotten to get rid of it is comment out the Spawn/Remove(chunk)/Destroy if statement. No idea why this is related to the issue though and obviously is essential.

I made another video where it might be abit more obvious if you focus on the wall on the right side as its moving, you will see the two platforms suddenly get closer together regularly.

I can’t really tell what the issue is via stepping through.
It happens at the exact moment a chunk is removed, destroyed and another is added.
It happens even when I make the prelab a basic cube.
I don’t get it :unamused:

Could you please fill out our form and send me your zipped project (without the Temp and Library folders)? Don’t forget to add a link to this thread.

When you are done, drop me a line here, so I can check our server.

Thanks Nina, I have submitted my zip file and the form. Thank you for trying to assist!

Thanks. I successfully downloaded your project. My hardware is 10+ years old, so things do not run super smooth on my device. I had to “play” the game a couple of times until I was able to see the problem occasionally.

Since I’m not able to recreate the problem every time, I suspect that the issue might be limited to the Game window, which is a laggy preview. When rewatching your last video with a speed of 0.25, I noticed that the game seems to pause for a brief moment when game objects get destroyed and/or recreated. This could explain why the platforms suddenly seem to shift.

See this piece of code:

chunk.transform.Translate(-transform.forward * (moveSpeed * Time.deltaTime));

The position depends on the duration of the previous frame (= Time.deltaTime). If Unity calculates things in the background and if a frame is slightly longer, that’s immediately noticeable.

You can also see the potential problem when you open the Profiler (Window > Analysis > Profiler) and run your game. There are huge spikes, especially when a chunk gets destroyed and created, so this could explain why the game is laggy in the editor.

Could you build your game and test the build? If the issue is also in the build, I’ll take another look at your project. If the issue is not in the build, the problem is limited to the Unity Editor.

Thanks for looking. I tried to build and run it- I think the same issue with the shifting platform is present :frowning:
It’s definitely harder to see, and maybe it’s my imagination that it seems less prominent… but it’s still there.
I looked at the profiler, the frametime definitely shoots up (I don’t understand the details enough to explain why), but I don’t know why that would cause a transform shift- it’s only the one platform, the others are all consistent.

If it’s less prominent, it might be that the problem is indeed caused by the creation and destruction of game objects that are active in the scene. A more performant solution would be to recycle the already existing chunks.

Since the jittering does not break the entire game, I would recommend to complete this section first. If we try to solve the problem right now, it might be that we cause conflicts with Stephen’s other ideas. Once you completed the game and if the issue persists, upload your game via our form, and message me again.

If your thread is closed, write me a private message, and I’ll reopen it.

I decided to go and download Stephen’s finished project from GitLab and try that. Initially I couldn’t see it, but after some time, and with separating the tiles and turning off all the other features/distractions, it was definitely still there. I realised it has to be my system or at least something making it worse. I ended up turning off a bunch of functions like windowed G-sync, frame rate limiting via nVidia settings, AutoHDR, RTX HDR…you name it. and…It got way better. I feel like it was always consistently gone, but was so much better it MUST be something related.

I think it’s enough to just drop looking further into it. Thank you so much for trying, Nina. :sweat_smile:

It is certainly related to things in Unity. In the editor, a lot of things get executed that are not included in the game. That’s why the Game window is always a bit laggy.

However, to increase the performance, it is always a good idea to remove all things, especially packages, that are not needed in the game. That speeds things up significantly.

The other problem is that destroying and recreating has a huge impact on the performance as well. In this course, it’s usually not noticeable because our games are so small and our devices so powerful but, in larger games, we would have to implement an “object pool” to recycle the chunks instead of destroying/recreating them over and over again. If you implement such an object pool, I’m sure the “shifting” will be even less noticeable.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms