A quick comment on this lecture and refactoring in general

At some unknown point, I started perusing most of the comments for each of the lectures in this course (sometimes learning just as much from the conversations as from the lectures themselves, which is brilliant! :slight_smile: ), and often enough when I felt I had something to add, someone had already mentioned it, so they would get a like, and I would move on :slight_smile: There’s something I’ve not seen spoken of though (I may have missed it, so apologies if this is redundant), and wanted to give it a respectful nod, and that topic is “Refactoring”.

Every chance I get, I try to tackle as much of each challenge as I can (sometimes even managing to complete a future challenge before it’s mentioned flex) but I’ve always found myself slightly paranoid about writing code that’s “optimized” or even just written “the right way,” and those ideas (which may have sprouted from listening to too many elitists on a certain online overflowing stack that shall remain nameless :crazy_face:) have held me back from being bold in really digging into C#. The idea of writing code that you never have to touch ever again is lovely, but after watching the lectures to this point, I know it’s a fantasy. In short, thank-you for showing us (me) that refactoring is absolutely A-OK; that I can write code, come back a bit later, feel contented in my previous efforts, and then tear it all to pieces, making any number of alterations without feeling any guilt, sense of inadequacy, or personal failure. :slight_smile: For a stark-raving perfectionist like myself, this means a lot. Cheers!

2 Likes

Truth!

And here’s a dirty little secret: We don’t give you the most optimized code in this course. There’s a lot of room for refactoring!

Thanks for that, Brian :smiley: I went through the Unity 3rd Person Combat and Traversal course in November and Nathan had run through some optimization practices that I’ve not seen in this course, so I had been wondering. An example would be using Vector3.sqrMagnitude vs Vector3.Distance when comparing the distances between two vectors. So I’ve written some of my code for this course using what I learned there, but… here, I’ve also realized that sometimes you actually need to know the distance, so that little method is perfect for the job. Having the largest selection of tools at one’s disposal is only a good thing, so long as you can learn where and when to employ them effectively :slightly_smiling_face:

1 Like

I feel the same stress when writing code. I think to myself “Am I going to be disappointed reading this later?”. Sometimes I look at code I wrote years ago or even just last year and I have a good laugh.

4 Likes

Wait until you have 25 years worth of code everywhere and you look back at some of those really old ones…

2 Likes

I’m looking forward to that, actually :slight_smile: I’ve taken the last two months off GameDev.tv courses in order to start building the framework for my own game. You guys have given me so many tools, so I wanted to try them out, and I’m hitting a learning curve similar to when I started Unity/C# with your courses 10 months ago, and am loving it! This last month I’ve spent working on a targeting system for implementing skills (like spellcasting) that have an AOE. Conservatively, I’d say it’s gone through four major refactors, grin but realistically, even though it’s only 10 classes, some of them have been renamed a half-dozen times and their function now is totally different from when I first sat down to muddle my way through. :smiley: Lectures like this one really helped me overcome the fear of making “mistakes”. Just get the code working… then hunt the bugs, then optimize it :slight_smile:

@Ian_Mclennan The disappointment and fear has slowly been replaced with excitement :smiley: I’ve discovered that I love deleting old, useless code (and by “old” I’m talking about code I wrote the day before, because I’ve not been coding long enough to have really old code yet :smiley: ) It’s become a metric for gauging my own growth, so although it’s like I’m looking at the work of a coder that we might ridicule in countless memes (yes, I’ve recently discovered programming memes) having full authorship lets me be ruthless in fixing what I see, until I can sit back, satisfied with the improvement, and say “Until next time”, then shelve it for a few days or weeks and come back with more experience and a fresher understanding. :slight_smile:

@Arquoono
I’m glad to hear that. As an aspiring indie game developer, I too am working on my own game. I started working on it last year, having no prior game development experience. I thought “I’m a software engineer, how hard can this be?” As it turns out, I had a lot more to learn than I originally thought. It’s been good to look at what I was able to produce before and after these courses. I’ve seen a lot of personal growth, and now I’m in a spot where I think I can realistically produce a game and put it on the market.

If you feel comfortable sharing, I’d love to see what you’re working on!

Truth. I once heard these words from another indie game developer:

2 Likes

I’ll see your 25 years worth of code and raise you 40. :stuck_out_tongue:

2 Likes

Glad I’m only an observer in this poker match; I’ve fallen too far in love with game dev to want to fold :smiley:

No way, never fold! Our numbers tell you that coding isn’t some flash in the pan hobby you do for a year and forget about. It can be a lifelong passion.

1 Like

Great discussion here. One thing I’ve struggled with (or maybe it’s that I don’t know an efficient way to do it) is refactoring the game objects/assets.

The IDEs do a great job helping you refactor code, but it’s sometimes just plain hard to refactor stuff within Unity. An example: We have the root arrow prefab and the fireball prefab. They should both be prefab variants of some other prefab that doesn’t exist yet. We also have and equipped bow and equipped sword but they share no common prefab so we had to add a Weapon script to each.

Our game is small now so these refactorings are fairly simple but this could have been an issue if we waited longer.

So the question is : is there anything that can help us “refactor prefabs” (for lack of a better name)?

P.S. I think I saw something on a unity forum once by the way that suggested to put all similar prefabs as children under a common empty game object and for each “variant” to enable or disable the children that you want/don’t want to be part of the variant. Was curious if that’s a viable way or if there are better ways.

PPS. I couldn’t help but laugh when I saw the below because it reminded me of some funny stories:

I’ve seen instances where code someone wrote 5 or 10 years ago as the junior engineer comes back to bite them when they’re the director or VP. Great lessons learned for everyone.

1 Like

I wish . This is a weak spot in Unity development in general. If somebody came up with a tool to refactor prefabs as easily as you can refactor code in an IDE, I’m willing to bet it would sell like hotcakes.
There is an IDE that can help, however… JetBrains Rider can at least show you where a script is being used. within the code editor.

Not only is it viable, but if you look at the character prefabs Synty uses, that’s exactly what they do.

There has been some changes recently to prefabs that I think is a step closer

Visual Studio does this, too. At least mine does, but I have Enterprise Edition and I’m not sure if that’s relevant

2 Likes

Woah! I’ve been using an LTS 2022 since it came out. Totally missed these changes! Being able to switch Prefab Variant parents is a game changer! I’ll have to review the fbx to prefab section further.

1 Like

Wow. I’ve also been using 2022 LTS but didn’t catch any of this. @Brian_Trotter Would love to see some stuff from GameDev.TV incorporate this because I’m not sure I fully grasped everything Jason was saying in the video. It seems like it has huge potential.

I’m using VS Community 2022 (the free one) and I noticed that feature about very recently. Not sure if it’s new to Community or if it’s been there all along.

1 Like

I think it’s relatively new. Microsoft has been playing a game of catch up with JetBrains (the maker of Rider). I don’t exaggerate when I say that Rider is hands down the best editor for Unity, and the best investment you’ll ever make in your coding journey. It’s not free, but the price does come down over time as a loyalty bonus.

Privacy & Terms