When different parts are being created at and moved away from (using CFrame) some areas of the game within a single frame, all similar parts in that area won’t be rendered for a single frame.
This happens in a way that is spatially consistent - my guess is that the flickering we see is caused by an entire “cluster” failing to render in that frame.
The bug does not happen if the parts are destroyed or are made fully transparent (however the bug still happens if the parts are moved a frame or two after)
And it only happens when the camera is at very specific CFrame(s) and is affected by the size of the viewport, so it can be difficult to reproduce arbitrarily.
Also, this bug appears to be worse if the added parts were already in Workspace beforehand, but creating them on demand is still pretty problematic.
Two videos
The bug happens both in studio and in live games. All testing is on PC, I’m not sure if it happens on mobile. The following reproduction place file was created with Studio Version 0.571.0.5710526 (64bit).
rendering_bug.rbxl (404.5 KB)
(Since posting I have updated the reproduction file to show a yellow reference part, which never gets modified in code, but will flicker when the bug occurs.)
EDIT: The bug appears to be related to where parts are moved when being CFramed. Moving them to (1e9, 1e9, 1e9) causes the bug, as we see in the reproduction place file. The bug does not happen in the place file if we move them to 1e8 or 1e7 instead. However we also get the same results if we move them to 1e11 or 1e12. This may mean that the move distance / exact position affects the camera CFrame required to observe the bug, in which case the bug could still be occurring, just from another perspective that the place file was not calibrated for.
Notes for testing with this place file:
-
Test using Play Solo.
-
Make sure you are using device emulation with HD 720 (1280x720) selected, as the test data is calibrated to work with a viewport of exactly this size. The bug happens at other viewport sizes, but the exact camera CFrame required to observe the bug would differ, which would make things difficult.
-
Check the output for feedback on what the current state of the three settings are (see the following hotkeys).
-
Press C to cycle between different camera CFrames (currently just “buggy CFrame” and “some random CFrame that doesn’t have the bug”).
-
Press R to cycle between different recordings of part creation/removal.
-
Press M to cycle between three different modes (see below for what they are).
-
The red outlines represent my guess of where rendering clusters are located, as per information from this thread (and the specific post): Part Instancing - pre-release announcement - #18 by zeuxcg
-
The green outlines are just where the red outlines AKA clusters intersect the white background surface. Neither the green outlines nor the background surface matter for reproducing the bug, they’re just there to make things easier to see.
The three modes:
Create → Move (Bug happens, lots of flickering)
- When parts need to be added, they are created on demand. So we just create a new instance, CFrame it, and parent it.
- When parts need to be removed, they are just CFramed to some really far away location.
Create → Destroy (Bug does not happen)
- When parts need to be added, they are created on demand. So we just create a new instance, CFrame it, and parent it.
- When parts need to be removed, we just call
Part:Destroy()
.
Pool → Move (Bug happens, but stuff mostly just gets hidden instead of flickering)
- Parts are created in bulk before we do anything. They are CFramed to some really far away location and parented.
- When parts need to be added, they are just CFramed to the desired location.
- When parts need to be removed, they are just CFramed to some really far away location.
(In this Pool → Move mode you may also notice that the added parts appear visible for a single frame, then are hidden in the next frame, then reappear in the frame after that. This is less of an issue for us, but it may be related and either way seems to be another bug.)
Expected behavior
Collections of parts should always be rendered regardless of how parts are being added or removed from the nearby area. There should not be a flickering effect caused by parts being moved out of the area/cluster, and details of the camera should have no effect on this stuff.
In our game we can have quite a lot of parts that need to be created and deleted, so to be as fast as possible we pool the parts and “delete” them by simply CFraming them to a really far away location. This bug makes our approach problematic as it introduces quite a lot of visual flickering if a player happens to have a bad camera CFrame.