Is my computer too slow to keep up with code?

Hi, I’m currently making the game snake for a school project, and I’m trying to get creative with the sprites to make the snake appear to be continuous and slither instead of just squares.

I think I have the sprite part figured out in a way that involves setting the correct sprite and changing the flipX and flipY accordingly. But when I run my game it seems that the computer is not able to keep up with me code because some of the sprites are not being flipped correctly.

Is it possible that the computer cannot handle setting the sprite for each piece of the snake and the flipX and flipY every time the snake moves one space? I’m fairly new to coding and don’t know if this is not something the computer can do quickly. Or is it more likely to be an issue with my code?


No it is not posible, you might have some bug in your code if you share it with us maybe we can help you.
If your game is really cpu expensive it will have lower fps, but it cant run some code faster that other unless you are using threads that dont ever use them if you are learning cause are complicated.

You can use Unity profiler to see how high the performance impact actually is. I would guess that it is not a performance thing, but a bug in your code. If you can always reproduce the issue in certain way, then you can use a debugger to figure out what is actually happening.

firstly, your issue is always in your code. :wink:

secondly, I bet you’re doing a mistake of using GameObject.Find and GetComponent<>() in your update methods, because most people in the forums here do that.

those functions are slow. you should only be using them once, and store the found references in variables, and then just work with the variables.

but even this wouldn’t cause any kind of “unity not being able to keep up, thus skipping steps”.
if your code were too slow, the whole game would just slow down/framerate would decrease, but code wouldn’t get skipped.

your issue is in how you’re iterating through the snake’s sprites, obviously, your loop is skipping some, or the way you collected all of the snake’s sprites, missed some, because you’re collecting them in the wrong way.

how about you post the actual code? it will be easier to point out where you’re making a mistake :wink: