Snake "add segment" logic results in visual jitter

Godot Version

4.3

Question

I’ve made a snake game, but once the snake is ~15 segments long, adding a new segment always results in a visual jitter. The tail is gone for one frame and back the next when the snake grows. I’m not sure why this is happening, as I was careful to ensure the position of the new instantiated “snake segment” scene was at the correct spot. I’ve tried a few different debugging techniques and none have gotten anything. As it’s only one frame, it’s hard to capture in video too.

I’ve tried breakpoints. I’ve set one in the debugger on “eat food when snake is already 15 segments long”. That breakpoint gets hit as expected, but when continuing, there is no visual jitter. This makes me think I am missing some optimization

If you could review my code and run it yourself, or let me know of other tools I can use to investigate, that’d be great :slight_smile:

I was able to solve this by adding a “backup_segment” that was pre-instantiated but hidden. Kinda saddened that Godot has visual artifacts with such a simple game, please let me know if there’s any better way to do this!

Ref Visual jitter when snake is 15+ segments and eats food · Issue #12 · mark-wiemer/super-snake-sandbox · GitHub