Unity/Game dev notes + book recommendations
I'm now finished with most all of the programming for my big game project- all the code required for the entire game has been completed- I'm sure some small things will pop up and there's still a lot of testing to be done by third parties BUT all the components I need to make the game are done-
Working on this, the second iteration of this game and the first one using C# scripts instead of Playmaker fsm's for everything started out pretty chaotic- When I started it I knew a little bit about programming but NOTHING about clean programming-
I had huge classes that did all sorts of things- my data was mixed with my logic- it was a mess-
I kept working through it though- refactoring as I learned more-
Now my classes are much more modular- I finally got it- when you start out you are so excited to get things working you ignore your working practices- instead you want to "finish" the script/mechanic and move on to the next one- leaving behind a hodgepodge mess of classes-
Here's an example of my new practices- the first class just receives a call to switch something- it doesn't care what and fires a SwitchedOn or SwitchedOff event- the second class checks to see if the player has a certain item or items, a key, or amount of coin- or a combination of all those things- it fires events on success or fail- in the image its set to flip the switch on success-
In the past I would have put all of that code in the same class that used it 0_0 From making a ton of shitty things I learned with great help from learning materials to create re-useable modular components-
Here's another example with my health class- the health class doesn't take the damage itself- the damage is taken by the ReceiveDamageToHealth class- I did this in part because I wanted the health script to always be at the root game object and the DoDamage class looks for an IDamagable interface on the object it hits- Given those two things in order for it to work only the root object could take the damage- I needed to be able to have an object receive damage from anywhere on its object if I needed it (Collider on head, collider on hand etc)
So now the Health class just manages the health and calls an event on death- it doesn't process the damage- the Receive... class does that- I also implemented DamageCheckTable's- its a simple scriptable object class containing enum lists- each damage dealer and damage receiver has a table- they are used to see if the objects can damage each other-
The health amount is exposed in the image for debugging purposes- its set by another class on initialization-
Trying to debug things and not being able to easily is what really pushed me into writing more modular code- I tried to do it "my way" and it was terrible so I sought all the wisdom I could to help write better code-
These were the most helpful resources for me in writing cleaner C# for use with Unity-
Book ----> Clean Code
This book is magical manna to the lost messy coder
Book ---> The C# Players Guide
This book is a great user manual for C#- awesome reference with great examples
Youtube channel ---> Unity3dCollege
This channel covers a lot of intermediate/advanced Unity coding stuff not covered anywhere else
Youtube Video ---> Schell Games on Scriptable Objects
This presentation blew my mind! I got their code and went to work implementing many of these things in my game which added muchly- not a word but I don't care- love this presentation!
Here are some of the lesser known Unity assets that I'm using in my game that I love- the full list is linked at the bottom
Easy Character Movement
I use this on every game I make now- It's very easy to implement/modify and has great performance- Includes a third person/first person/ and Navmesh agent controller!
Master Scheduler
If you've tried to squeeze all the performance you can out of NON-ECS Unity code you've probably used threading and hit the "thread safe" walls- this scheduler works a little differently but you can run any code and make sure it doesn't lockup/cause spikes in Unity
Camera Controller
I use this flexible and elegant camera controller in all my games- third person camera systems(especially collision handling) are difficult to get right and this one does a great job with everything
Non Convex Mesh Collider
This one has a very programmerish name ^_^ What it does is... automatically generates primitive compound colliders for your odd shaped objects- saves a TON of time and performance(vs. mesh colliders)
Full list of Unity assets I'm using and recommend
This latest month or so of coding that I just finished came after outlining the gameplay for the entire game which you can read about in a previous post here- So after finishing that outline there were some things I needed to be able to do that weren't built yet- so I built then and cleaned up/streamlined the other code as well-
I know that if you are reading this you've heard a lot about this game but haven't seen much- I've been working on everything but the art so far BUT the time will come to get to the art then you can expect a torrent of strange awesome coming from me ^_^
In the following run-on sentences when I say "design" I mean draw on paper then model in 3d-
What I'm doing now is designing the rest of the enemies for the game- all NPC's are done(and modeled etc) + 15 or so enemy types(modeled + animated etc)- will probably do 20-30 more enemy types- I also have to do additional level design-
So after a month or so of more coding now I'm back to drawing and doing creative stuff until its back to coding to make it all work-
I'm looking at 2020 for releasing this game- 2019 is going to be a busy year for studio me ^_^
Best,
M.
Brought to you by professional weirdo M dot Strange.