# C# Managing a growing project

## Recommended Posts

Hello all! Thanks for taking the time to read this post.

This is a bit of a strange subject, but a very important one nonetheless in my opinion. I've been programming for about 7 years now, and over this duration I've made over 10 small but complete games. Over the past few years, I started working on a bigger project, and this has been through two prototypes. I've noticed that every time one of these prototypes reaches a certain size, the code becomes more and more intertwined and interdependent to the point where productivity slows to a halt and eventually just stops.

A lot of people tell me to "create small games" and "see them through to completion", but I have indeed done this, and this problem seems to persist. I'm not working on something overly ambitious or impossible to complete, but it always seems like when I try to create a game with any kind of substance or complexity, coding very quickly becomes this awful chore of backtracking, and progress slows and slows to a halt. I've done lots of research into programming patterns, and I write my code very meticulously with lots of comments and strict formatting, but I can't seem to jump this barrier.

For the first time ever, recently, I decided to COMPLETELY document every single aspect of my game, so that creating content won't involve me having to over-engineer and future-proof my code in the hope of future additions. This way, I can completely design the architecture around this content and then shut the doors and agree to not add any more content, no matter how tempting it may be. However, I'm not too sure how to go about starting a new project in a way that will ensure quality control and a nice balance of readability/cohesiveness/modularity.

I wondered if any of you have the same problem, and if so, how do you go about combatting it? Is there a tried and tested way create an architecture which allows the addition of code without causing a rippling echo throughout all existing code? Is there some form of diagramming or pre-planning which can help minimize this risk later down the line?

Thank you,

Zuhane

##### Share on other sites

What I've learned from the years I write code now is that it dosen't always depend on comments because comments don't make a good code base. Thinking about what should be achieved with the code base before writing the first line is much more important because I ended up refactoring a projects logical structure in the past more times I refactored code from changing content. This is why I splitted large projects into a more modular structure where I have a core code base that is modular extended by functionality of logical different topics.

In C++, this is quite simple by splitting the project into standalone projects and linking them together as static library while you havent this kind of convinience in C#, you can split everything up into several libraries to include into your final application.

My development tools for the game engine written in C# stay all in the same directory but have there own subdirectory. Anything is build into the root directory (Tools). I then have a core library that contains certain subset of C# code that any other of my tools shares partially. This way I have the same code base for all my tools.

Using my dev tools leaded to having a shell application that is dynamically loading my tools into one single program during runtime. It is capable to do all the build setup, remote attach to my game engine and even manages the code base by managing the modular parts in packages. I took this from NPM here but a little more simplified enabling my development process to dynamically drag in/out code packages/ modules of my current project depending on the requirements I currently have in this project.

If you are working in Unity, you are something bound to the engine (I took Unity in here because you tagged just C#) so its project structure and building pipeline. But managing your modular code in several subdirectories should work here too and you are also able to declare code as your core or main module.

Second, using namespaces. I know that this is a topic to discuss about because half the people tend to not use them while the other half overcomplicates namespaces. Namespaces are a great feature to logically split up your code into functional sections. This means that IO classes should live in there own namespace, encryption classes should live in there own namespace and so on.

Third and least, keep it simple and be as lazy as possible.Simple class names, simple but meaningfull function and variable names make life easier. Using consts for constant values makes it easier to change them in certain code base and most of the time you just need static functions (from my experience) so making a class for everything is pointless. With being lazy I mean that a lazy coder wont copy/paste the same code, do repetitive stuff by hand (just like filling out a table of key codes) using some kind of quick n dirty tool to do the work and writes as less comments as possible except for those that are meaningfull too

These are some of my experiences I made, someone will have other experiences made and at the end you have to choose what fits best to you

##### Share on other sites

Hey Zuhane.

I recognize your effort, 10 games is a certainly an accomplishment, no matter the size of the games in question.

I'm sure that throughout that endeavor, your experience in programming has grown. However, our experience grows in many ways, and programming, overall, is a big beast to tackle. So, like always, there may be areas in which we need to improve that we haven't been paying much attention to.

I see 2 possible problems here:

1) A classic problem of tightly coupled code. What this means is that your method clearly forces apply several changes in your codebase whenever you need to apply a small change somewhere. This is a problem that gets more and more noticeable, the larger the size of your code base, and is usually solved through programming patterns, software architecture, and similar software engineering solutions.

However, you mention you've done a lot of research into programming patterns, which either means you're lacking in your program architecture, or...

2) Perhaps you're attempting to make projects that are simply too big for one single person, and need to consider bringing additional programming brawn. You don't mention whether you're alone or not, so I don't know if this even applies.

## Create an account

Register a new account

• 9
• 13
• 40
• 15
• 11
• ### Similar Content

• Hello,
I want to get into coding again by programming a 2D platformer to get started, but i don't know if i should use Java or C# with the unity engine.
I am pretty fit with Java, but with c# i have to start from scratch. What do you recommend and why?

• Ok, firstly, Hi.

This is my first post on this forum. I am an Indie Dev making my first game so bear with me when I say dumb stuff, I'm on a huge learning curve.

My first question is about inventory systems for unity. I am trying to make a survival type game with crafting. I have purchased Inventory manager pro by devdog from the unity asset store and it seems like a pretty powerful assett but for an intermediate coder its a little tough to use.  I'm beginning to wonder if it was the right purchase.
So my question is.... does anyone have any experience of inventory plugins / systems for unity and can anyone reccomend a system to me?
It needs to have the following: Loot system, crafting system, character sheet, blueprint system,  character stats system. Ideally with as little coding as possible.

Thanks

• I've got a bug with my brick breaker style game. The bricks move down one line at a time ever 1.5 seconds. What appears to be happening is occasionally the ball will be just about to hit the brick when the brick moves down a line, and now the ball is behind it. I'm not sure how to fix this. I have two ideas but I'm not sure of implementation. 1 solution would be to check where they were and where they are going to be before rendering the frame. Then if they crossed paths, then register the brick as hit. Solution 2 would be change how the bricks move. I could maybe slide them down line by line, instead of a jump down. I'm not sure of this will fix the issue or not. Any ideas?

• Once again Unity is frustrating me to the point of insanity.
What I am looking for is a way to find a ray intersect with the edges of the mesh, using Unity's already made collision system. I want to point out that I know how to do a line intersect, what I want to know is if Unity supports this already.

The image above shows how I sweep a ray,intersecting the mesh. The top green image shows what I want and the red shows what Unity is giving me.
I want to know if there is some way, to find the edges in Unity without creating a custom line intersection tool.
Most engines I know don't use rays for this but instead use a plane like this:

I checked the Unity "Plane intersection" but it is just a ray cast. It will still need me to find the vertices on the collision mesh to cast the ray from; if I am doing that then making my own line intersection tool is better.

I looked online and can find anything on this. Also I don't want to cut the mesh, so I don't need a way to know what side is what.
Does Unity even have collisions that support edge only detection?
• By JuliaAxt
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(Rigidbody2D))]
public class TapController : MonoBehaviour {
public float tapForence = 10;
public float tiltSmooth = 5;
public Vector3 startPos;
Rigidbody2D Rigidbody;
Quaternion downRotation;
Quaternion forwardRotation;
private void Start() {
Rigidbody = GetComponent<Rigidbody2D>();
downRotation = Quaternion.Euler(0, 0, -90);
forwardRotation = Quaternion.Euler(0, 0, 35);

}
private void Update() {
if (Input.GetMouseButtonDown(0))
{
transform.rotation = forwardRotation;
Rigidbody.AddForce(Vector2.up * tapForce, ForceMode2D.Force);   (The name tapForcedoes not exist in current context)
}
transform.rotation = Quaternion.Lerp(transform.rotation, downRotation, tiltSmooth * Time.deltaTime);
}
}
void OnTriggerEnter2D(Collider2D col){
if (col.gameObject.tag == "scoreZone")
{
// register a score event
// play a sound
}
{
Rigidbody.simulated = false;   (Rigidbody does not contain a definition for `simulated´)
//play a sound
}
}

}