How important is it to you to understand every single bit of code you implement?
Hi there!
I am a beginner-intermediate level programmer using C# and Unity to get into making games. The genre I really want to get into making, naturally, is both extremely niche and difficult to program: RTS / grand-strategy. There are often several complex systems interacting with each other throughout the game, and especially as gameplay progresses. Rome Total War, Mount & Blade, Civilization, Stronghold Crusader, etc. are my main influences.
I am almost immediately running into challenges understanding entire scripts, as things like RTS camera controllers are invoking calculus and physics, neither of which I studied in school. Since this was basically step 1 for me, I'm a little intimidated to move forward without a background in physics/advanced math. I have no issues whatsoever finding good resources, following directions and copying code, understanding the general flow of how the script works, and altering the behavior to make it work for my game.
After watching a few different tutorials, I now have a camera controller that feels great to use and functions perfectly. But how important is it to understand the script, line by line moving forward? Is it worth browsing Udemy/Coursera for to study physics and calculus for this, or is it better not spending the time unless it breaks, the ol' 'don't fix it if it ain't broken' approach?
Thanks!
Edited 24 Mar 2025. We only hold this version.
About this post
- Posted
- Archived
- Edited
- Score
- 11 · 79% up
- Kind
- Text
- ID
- 1jiu0mr
71 comments
This may not be a popular opinion among people who only got into programming through game dev, because they don't understand how deep into shit you can get when you combine a bad codebase with a low understanding of said codebase, but trust me when I say, as a software engineer by trade, that it's absolutely imperative to take the time to learn programming properly and understand the code you add to your game.
"But releasing games is about moving forward and developing quickly, noone is gonna read your bad code" - this is based on a false premise that writing bad code is faster than writing good code. See the design stamina hypothesis
Oh as a professional game programmer I totally agree with you.
You need to understand all the code because there are going to be bugs in it you'll need to fix or you'll want to extend it.
This is my thought. I can see several scenarios where I copy until the tutorial series runs out, and then I have no knowledge of how to implement anything else that someone hasn't already made. Esp if it's a system rooted in physics, or draws on calc formulas, etc.
One system I already ran into this with and am currently stuck on: unit formations and movement. I see people talking about the hungarian formula for units to get to their position as quickly as possible. It'd probably take me a long time to find that and implement it on my own, if ever, with my current knowledge lol.
Thank you. So to be clear, you think it's worth spending time on Udemy/Coursera with physics/calculus courses?
Please correct me if I'm wrong, but...
Knowing how your code works and what it does doesn't mean you have to be able to solve those problems by hand, though.
Knowing your code uses x formula to accomplish y purpose is sufficient to be able to use that piece of code for said purpose.
Personally when I get to those I will be using textbooks. Calculus is standard in maths courses so materials are not hard to find. I’d treat online resources as extras. That’s just me!
A couple of books might interest you: Essential Mathematics for Games and Interactive Applications (Verth & Bishop) Game Programming Algorithms & Techniques (Madhav)
Freya Holmér also has a playlist on YT.
Not sure the full contents of what they all cover.
It’s better to understand it, but it’s not required to. If the goal is to make a game and you’re learning, I’d say the ability to move forward should be prioritise over understanding everything. Make an effort to understand in the beginning but if it’s not something that’s clicking right now, it’s better to move forward as you can always come back to it later.
It’s also worth noting that professional software engineers don’t understand every little detail of what’s going on. Many sit on some kind of abstraction and don’t necessarily understand all the details of what’s happening below them. And this isn’t limited just to low level technical details, but even of the algorithms being used.
understanding what your abstraction layer does at a high level is important. This includes the game engine you’re using. People don’t need to know the exact ins and outs of the memory allocations happening under the hood when you create a new game object in unity, but understanding the potential consequence of creating 500 instances of an object in a single frame will keep you out of trouble.
Oh as a professional game programmer I totally agree with you.
You need to understand all the code because there are going to be bugs in it you'll need to fix or you'll want to extend it.
I agree, even when I use others code or even AI generated code I am able to understand it and often implement it in other areas when it feels suited.
I'm by no means a code master but my code is manageable for me. I often get called out for my code but unless it's an obvious solution to my issue I just ignore it until I understand it better and see if it matters.
Sometimes it's ok to have a black box plugged in, though. Like, if OP's camera controller is standalone and will never need to interact with other code, does it matter if they don't really understand it? I pop a Rigidbody onto an object, I don't need to know how all the physics works, it's just a black box that does that what it's supposed to.
Oh as a professional game programmer I totally agree with you.
You need to understand all the code because there are going to be bugs in it you'll need to fix or you'll want to extend it.
Make a copy of whatever you're playing around with and go at it with a hammer breaking things to see what happens. If you see some operation being used that you don't understand, route around it and see what happens - it'll break, but the way in which it breaks will teach you about why it was there in the first place.
To to rewrite scripts "in your own words", meaning you can still use those scripts as a source, but try to change up the way it's organized while getting the same functionality.
It does become important you understand what everything is doing, but that doesn't mean you can't fake your way along while you learn. The undo button and source control are the biggest advantages software devs have compare to learning anything else - you can bake 1000 virtual apple pies to experiment and it'll only have cost you some time.
Wonderful insight, thank you!
In my opinion it's really important. I really hate this new trend of rookie game devs clobbering together YouTube tutorial code snippets and chat gpt. The level of programming ability you need for programming video games is as low as it gets. I really don't understand why people can't just actually learn to code.
This is directed at me 1-2 months ago. As the code got bigger it got impossible to manage since I didn't even know how it was structured. I still get help from AI but now it's really narrow and specific.
I don't think that trend is anything new, it's always been like this. At least since unity became a thing
Ooof. This is a huge question which could be debated for months 😅 I'll try not to get carried away, but just wanna say that I spent 4 years of my professional career in building and releasing an RTS game. And fyi, I still remember updating and re-fitting the camera controller - that someone made before I joined - several times 😂 I also became lead programmer on the project and was involved in almost all parts of the code in one way or another.
I just wanna mentioned early that you basically don't need calculus unless you're making a PID controller. Perhaps that's how your camera controller does smoothing. Sure you can apply various math to make smooth motions but that's high level polishing and only useful in a small percentage of systems. Most motions are very linear and the most useful math is vectors and lerping. The game engine offers other options for rotations as well as some smoothing math functions like SLerp etc. You might find some trigonometry needed on occasion too. Of course a general math intuition goes a long way. You don't need to understand Quaternions either, but it will be useful to get acquainted with the rotation functions Quaternions and Vector3s offer like "Rotate towards", "Look at", "EulerAngle" and "SignedAngle" etc.
But for the wider question, here are some takeaways. Everything here "depends", and you could argue both sides of most things here imo. For example:
Camera Controller is a relatively independent component and you could likely get away with importing something that somebody else made. But here are things that you might want to do with that camera, which could or could not prompt you to understand the controller better:
Each of these could be made without the controller code, and thus you may get away without ever looking at the camera controller code.
But in general - most code will not be that independent. Most code will be coupled in some ways. There are good coding practices that aim at reducing this coupling but even being really good and strict about those will still not let you just develop the game as a modular jumbo of different code imports.
Note: In general, code you import will almost never fit your needs perfectly, and require modifications.
So the other point is - You should be able to understand all code. That's a blanket statement. If something works and you don't need to change it, great, you save time. But you eventually want to be able to dive into any code and figure out how it works in broad strokes so you can locate relevant areas you might want to modify.
Without this skill you might lose a lot of time making modifications that weren't really necessary. Maybe you spend a day writing a new script when you could have solved the problem by adding two lines to an existing one. Maybe you don't spot that a function in the code already does exactly what you wanted.
Being able to read code others made takes practice. The advantage of being a solo dev is that you can get away without practicing this too much since you will generally recognize or remember your own code most of the time.
If you work in a team of others, you will frequently encounter code you didn't write. And if it's a large project, you won't even have the capacity to remember it all, and you have to understand code on the fly on a daily basis. Sometimes you can ask a team member to explain some code, but they may not work for the company anymore so you have to figure it out on your own.
But back to the question.
Code that you make yourself, yes you should fully understand what code you are writing. This is also what makes you able to take away from a tutorial and apply it to your own custom needs.
Every time you need to update or rewrite a system to facilitate a new feature, you need to fully understand that code to find a good way to change it so it meets both the old and new requirements. Ideally each piece of code only has a single purpose (google SOLID principles) to reduce these types of complexities, but realistically a big project, like an RTS game will have some entanglement. And unless you're on a senior level you will struggle to both make the code do what you want while also satisfying multiple good coding principles. And you shouldn't try too hard anyway tbh.
"Don't let perfection stand in the way of progress".
Focus on what lets you progress and what motivates. You will make unmaintainable code in the beginning. And that's okay. You will find that as you iterate on your project, the earlier code you wrote falls apart, and you might bang your head against the wall trying to fix it. You will find that it is sometimes better to rewrite some systems instead of salvaging them. I still do rewrites myself when I look back at code I wrote a year ago.
"Don't start with your dream project first" - this statement comes from the above. You are doomed to make many mistakes early. If you really want to finish a project, you need to stay stay motivated and have discipline to keep going when you're not. This is incredibly hard if you keep fighting your own code from two months ago because you were less experienced then. To make a big project, it's basically a requirement to develop code that is easier to maintain as you iterate and add features. Aka experience.
But - that doesn't stop you from trying to make RTS projects. Or grand strategy projects. Just don't expect your first "MyEpicGameProject" to be the one that crosses the finish line.
One final point to mention. As programmers today, we already stand on the mountain of accumulated progress of those before us. We never have to fully grasp all the code we're actually utilizing. That would be a tremendous undertaking. You can and should trust that when you ask your camera position to move left, then everything being rendered on screen appears to move right, without understanding how the rendering works, and by extension maybe even how the camera controller works.
Where that line is drawn is relative, and it depends. Great tools lets you apply them to your needs without reading their internal code.
On the counterpart, I have found myself diving into Unity's internal C# Animator Controller code because I wanted to do something that wasn't covered well by that tool, and dove into the A* Pathfinding Project code to make additions for my custom needs.
Hope this answers questions, and apologies for the wall of text. Feel free to ask any RTS questions though. I enjoy talking about that topic.
Wow, thank you for sharing - this was so helpful to read!
I would love to learn more about the RTS you worked on. It would be really interesting to be able to see a thing you made and be able to ask you about it directly. If you wouldn't mind sharing the project here or DMing a link, I'd love to see it! Also, if you have any insight on the interaction between development and design, I'd love to hear your thoughts on that. I have most of my systems already planned and can definitely foresee a potential mess - I likely need to scale down even after I have a better understanding. Esp, as you are implying, because with many interacting systems, if you break one thing you could end up breaking 5 or 6. So I will absolutely look into good coding practices and at least let it inform my decisions.
As for the camera controller, the script uses dx/dy for camera rotation. As far as I know, that's the only part of the script that uses calculus but it's definitely in there. Use of vector3s, Euler angles, and Quaternions are all in that script as well lol. This is the second camera controller I've tried, and it feels great to use. It could be that the person who made the script either was unaware of Unity's built-in rotation features, or maybe even created the script before that feature existed (I think the video was from like 9 years ago)? Either way, the person seemingly did a great job.
My original idea was to just copy a bunch of different build-a-game tutorials, alter each to fit my vision, and with all of my bastard children I would have the foundation to start on the game I wanted (combined with, of course, studying C# as a language throughout that process). I will likely keep using this method to subsidize my learning, but I think after my first go of copying a series, it would be more beneficial to do that once I'm a little more advanced with C#. That way, as you mention, it will be much easier for me to start reverse engineering, deciphering what others are doing and why they're approaching things in the way they do.
I know it may not be necessary at this stage, but I do want to retain the option of hiring help in the future, for assets and potentially with complex systems if I'm on a roll and it could help speed up the development process. So, I do think at the end of the day, that seems like a super valuable skill to practice, because we can apply it to working in teams and also just being able to watch tutorials and build off of them more efficiently/creatively.
One idea that has really stuck with me over the years after reading Rise and Fall of Alexandria - they had the technology in the Great Library to make a steam engine nearly 2000 years before it was invented. Thing is, there were so many books in the library that nobody happened to read &/or apply knowledge from the combination of books it would've taken to create the engine. In that way, I am not at all above using other people's code for inspiration or as a foundation. The more we play around with existing ideas, the easier it is to imagine new ones.
The game is DwarfHeim. Our studio eventually bankrupted and the game is no longer listed on the steam store but there's a bit of articles and youtube stuff about it. I think someone even tried ot make a crack for it on Github. I can DM a link to the steam store page just so you can check the videos / screenshots there.
(And the reviews if you want to read what can go wrong on an RTS) 😂
"dx/dy for camera rotation" - If you see this in two-dimensional movement (like for a top-down camera) it can sometimes just be meant as a check for whether something is going horizontal or vertical or which angle it's pointing. "dx" just means the "delta" or "diff" of the x position from last frame. Or in layman's terms, how fast it's moving in that direction (movement per frame). And then "dy" is likely the same for the vertical direction. Hopefully there are some checks in case dy is 0 to avoid division by 0.
So by dividing the horizantal velocity with vertical velocity you can see if the direction is "more horizontal like if Abs(dx/dy) > 1 or vertical if Abs(dx/dy) < 1. It could also be that it's just doing some trigonometry to find the angle the camera is pointing. In which case it may do something like atan(dx/dy) or similar. Finding the angle could be relevant if the intention is to move the camera in the direction it's pointing.
If the above seems fitting, it's not calculus, it's just a ratio between directions to determine angle or to categorize a movement direction. Calculus is often more concerned with change over time, i.e. dx/dt or dy/dt. Basically how a position changes if the time changes. But for X and Y those are less dependent on eachother and it makes less sense to check "how X changes if Y changes" by applying calculus.
"copy a bunch of different build-a-game tutorials" - I think if you treat code implementations like these like placeholders you might get a decent start going. As mentioned before the problem mostly arises when you start connecting and combining things that perhaps were designed with very different contexts in mind. But having "something" instead of "nothing" is probably much more motivating to work on. Like if you have a world with trees and grass it's much more pleasing to iterate and test gameplay on it than if you just have a flat gray plane to walk around on. And I think that applies to code as well. Having some foundation of code / functionality makes it more fun as long as you don't have to fight those code systems. Might be a good mindset to think of the "bastard children" as placeholders with the intention to discard them for improved code replacements later. Don't take my statement out of context please 😅
"In that way, I am not at all above using other people's code for inspiration or as a foundation" - Work smart, not hard. A lot of programmers are lazy, and that is a good thing. Lazy programmers are more motivated to find solutions that require less work. One of the most important skills of a programmer is googling 😂 Your ability to use other people's code effectively increases a lot if you're able to understand how it works. But it takes time, and the most important thing you can do is to not get stuck on something that kills your motivation.
A lack of understanding will lead to being unable to solve bugs later. The simpler the game code, the more you could get away with, but a game like what you mentioned.. Don't risk blocking your progress later for some more progress now!
Thank you! This seems to be the overwhelming sentiment from people with experience, so I'm currently back to the C# course. I think my best plan for now is to keep my work on the game to the GDD while I plug away at learning the language and how it interacts with Unity. It can only help with ideas for design, right??
Get a proper design down before jumping into coding is a great idea in any case!
Also: you could learn coding as well by making smaller projects. Of course, if your dream is jumping into the complex one first that is valid, just requires more studying beforehand, and is more error prone!
Many games get released with dreadful code, I'd love to say don't worry about it, but as others have said it likely will trip you up at some point.
I would say however if the camera is self contained you don't need to worry about it. If it works, it works. You would likely only get into issues with everything else.
Tying to do things 'the right way' is the death of many many games.
I have done things "the wrong way" in a creative field and also paid the price. There's likely a happy medium, and I don't feel like I'm quite there yet with my coding knowledge but I'm getting close. More and more is starting to click. I appreciate the feedback!
If it's just a math equation, I can understand what the equation is for and copy and paste it. I'm not a math guy, but I understand what the math is doing.
When it comes to code itself? Nah. Definitely figure out what's going on. You can get by if you don't figure it out. I did a lot of copy-paste when I was starting out, but in the long run it hurt me. I'm not going to lie - sometimes I still copy-paste code! I'm fairly sure everyone does it. The important thing though, is you figure out what each line is doing. This isn't even just a personal development thing. Your game is different from every other game. Maybe those lines of code aren't doing anything for you. Maybe it's actively slowing things down. Maybe it's introducing a bunch more shit into the editor that odesn't need to be there. Maybe you'd like things to function differently and you could be changing that code. There's a ton of reasons why having random "idk what this does" code could be an issue.
Wise words.
Programming means understanding the problem.
A black box is different, if you can trust it. I don’t know how the C++ standard library is implemented. But I need to understand the tools I’m using - what they do, and what I’m doing with them.
Being “self-taught” through YouTube, I’ve done my fair share of implementing code that did what I wanted without knowing how or why.
But every time I’ve actually learned something I thought was too hard, like coroutines, while loops, etc. it has paid ten fold.
Understanding all code? Extremely important. Understanding all math formulae? Meh.
Put the complex math in a function named after what it’s doing. You don’t have to understand the equation, so long as you understand how to implement a math function in code. And write unit tests for that function if it’s at all important
I'm a complete amateur messing around as a hobby and no formal training.
Why would you not want to know what everything does? Isn't that part of the fun of making your own thing?
There's this trend right now of people getting into gamedev and then immediately quitting cause it's difficult. Often times they literally have zero idea what they're doing and aren't even really learning, just YouTube tutorials and AI or asking on Reddit for help.
For me personally, I am more interested in design than coding but I am interested in both. I can come up with ideas all day long, have given several modders feedback that made it into popular mods for different games. I absolutely love thinking about that stuff and it's almost all just letting your creativity flow.
Coding is super challenging. It's more like learning science or math. It's rewarding, it's interesting, it's fun. But it's just a completely different kind of experience. Most gamers just probably aren't interested in what's under the hood, and just want to see their ideas come to life.
I was hoping that it wouldn't be a big deal if I could find existing systems and piece together a frankenstein without having to spend too much time away from my other hobbies/chores, which I am not willing to give up to make a game. So I can see why a lot of people don't want to learn. But for me, I am pretty patient and determined so I'm just going to shift things around and keep carving out time to continue learning. It's just a passion project, so I have no pressure other than excitement.
You know every single bit of code you implement automatically.
The beauty of programming is that you don't need anybody's permission to learn it. No particular background is required, and the more you learn, the easier it becomes to allocate new learning in a more targeted and efficient manner.
Also, grand strategy games aren't particularly hard to program. They're hell to design, though.
Does it count if you did understand it when you wrote it but now it just looks like an unfashionable mess? This just happened to me trying to track down a corner case. Couldn’t understand the code so wrote a logging system. That didn’t exactly help as expected but it did make me realise the bug was somewhere else entirely and was an easy fix. The spaghetti code continues to work flawlessly.
You probably don't need to know the linear algebra that underlies the perspective math behind the camera, but it would help if you need to modify it. It's more important to know how your systems fit together
Well, that depends if you need to debug it. If you trust the code, it works just how you want and there's no need or desire to build on it, then you'll be fine.
That may sound an unlikely combination but it's how we use libraries and APIs all the time.
Focus on functionality first. If it works and you can modify it when needed, that's the important part. You'll naturally absorb more understanding over time through practice.
Most professional devs use libraries and code they don't fully understand. It's normal. Keep building!
You picked a really complicated genre.
As a master of RTS game coding I understand everything I'm doing. But that doesn't mean you can't get there. I didn't start off knowing this stuff, I had to learn over time.
My advice would be not to stress about it but push towards building what you want to build.
If you write your functions, organize, document, and name them well enough it becomes easier. But you should definitely “know” your code.
It's not critical to understand every single line as long as you get the overall idea and can modify or debug the code when needed. In my experience, using well-documented snippets to get something working is fine. You’ll naturally pick up the underlying principles as you tweak and extend the system.
When I started I didn't understand any of it. But fixing it when it was broken is what taught me the bulk of what I now know.
What I found most useful is understanding the concept behind the system. They refer to these as "Patterns". There is no programming in the concept, but if you know what it is supposed to be doing, you will slowly start to understand the structure of the code.
I'd start by reading this: https://gameprogrammingpatterns.com/contents.html
Then when you look at a code you are copy-pasting you can start to see each little component. Imagine it's like looking at the engine of a car and instead of seeing every bolt and gasket you see "motor, radiator, and alternator".
Once you start to see the larger components and you start to learn whatever language you are using, you can start to form judgments on how the code is doing what it is supposed to be doing. You'll find a lot of LLM code to be questionable at that point. You may not be able to write your own, but you can fix theirs and that's a big step imho.
I'm only one step passed this step. I still don't know all the language I need to but I can make most of my own systems and bug fixing is much faster.
My advice would be to always follow 'best practices' for coding even though it may seem redundant or over-engineered it will save you when you get to the point of needing to correct your old code.
I think an important part of this is that even if your code sucks, it should be structured. If you have code running In the background that's absolute ass, you can fix it later if it's encapsulated.
You want to understand input and output of what you write and you want to create robust black boxes.
You can geenraly trust engine features with this, so use them wherever possible, but build on top of them.
I don't understand most of my code...
Usually this works fine, but when there is a problem I'm like really screwed. Luckily for Ren'Py there is an awesome subreddit that always helps me out xD
I must 100% understand any code I implement, if I did not how could I implement it? Addons and Engine APIs I do not need to know how they work internally as long as the documentation regarding what a call works does is accurate.
For RTS/grand strategy dev, you don’t need to understand every line, but grasp the core concepts behind critical systems (e.g., camera math, pathfinding). Learn math as needed. Ship first, refine later. Use prefabs/assets for complex systems (A* pathfinding, DOTween for animations). For RTS-specific help, hit up r/Unity3D or the RTS Engine Discord.